From patchwork Tue May 15 21:54:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 913950 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-477730-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="le7IqYUg"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 40lrwH0R8Hz9s0y for ; Wed, 16 May 2018 07:55:25 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=oty0urSwwlyNWEeb1xurux7+Z876YqT9FhU948379J7UBo SjvGiOTZcgpQ9utq7Z3yGpcP5q9Nyb13zwaZhXl25CiudcihXnX23YoanWTlo9iC jJy+rl6+wZ5sbbK5yHSZGSY/XaN3DZcMsMDZwe6v21JDOTFVKI0B7qe98mCFw= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=2u3mbT9bomh1w46LlS01AW92cFQ=; b=le7IqYUgFe9wgYT0vG8D 0GmPDRFI2ztC1cG0wGUeVFaM4UUM/RCd7HjYey0zgXQOWRDIqX7/X/GK1mKFukbU ObH7vHSE+4TAjCCfz2scjgAW8jClfJI10m2MhHSjjz0R05dS36W3IR/WLZG/qSmS dVJ7faUY2mtQeWklcIUwKnk= Received: (qmail 110076 invoked by alias); 15 May 2018 21:55:18 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 110064 invoked by uid 89); 15 May 2018 21:55:17 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-25.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=category, cwg, 1560, CWG X-HELO: mail-ot0-f172.google.com Received: from mail-ot0-f172.google.com (HELO mail-ot0-f172.google.com) (74.125.82.172) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 15 May 2018 21:55:14 +0000 Received: by mail-ot0-f172.google.com with SMTP id i5-v6so2058858otf.1 for ; Tue, 15 May 2018 14:55:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=3msfXMv2TdJeFAJ8tcvy2buohSXGRVmgtyQZ3OXbSXc=; b=R/hDb36+MPgShfiF2x9Knj6ZJFoH0nK+0fPA6wm3nsJcwhm5CEdKCu7+PCFfnMUylO NHmFjUwBQB/FxtN+Il9rt4RitFhAmoBVfS3my7b/TU1qlJjY7rNDoFwm8LWZnbISVzTz XB1JH8vSGBT1KBOk+NC7DIo1QpzL0zr4OaeER7V01PjSD5QRyHkBP8092qU9js25fqdb N6FSJoWXEB/ZedKpogRkE5Z/5uSjKNVi3znd98DgX7iFBobXDi+h0FeONpDvhrlRXYN9 ikP2svg7g2if8Q3gpUHhExME3OAF68rcjve+O1SOYDEDmuCkwKb4X2naTVfU/mbcet0O UIuw== X-Gm-Message-State: ALKqPwfs2PYrORf/ZDIaN+TbTzmessXHp8RAQ/6D8XyeUlNr1gwT9zts LQ0vAruspbekeze+ljM4UHkcH03N51GcqwC9alsL/r00 X-Google-Smtp-Source: AB8JxZqNQqY6u+SD01PrSL/3kfTJoi+YDb9xbigbVT+K3CeGSUWaqtgxp7n4JYpGm9bDVeO5SI3dB1cIzCdf09aCniw= X-Received: by 2002:a9d:cc8:: with SMTP id o8-v6mr12223988otd.86.1526421312921; Tue, 15 May 2018 14:55:12 -0700 (PDT) MIME-Version: 1.0 Received: by 10.201.13.229 with HTTP; Tue, 15 May 2018 14:54:52 -0700 (PDT) From: Jason Merrill Date: Tue, 15 May 2018 17:54:52 -0400 Message-ID: Subject: C++ PATCH for c++/64372/DR 1560, value category of ?: with one throw To: gcc-patches List X-IsSubscribed: yes DR 1560 in C++14 fixed this rule to not do a gratuitous lvalue-rvalue conversion in this case. Tested x86_64-pc-linux-gnu, applying to trunk. commit c7b8b79f72865740ead84aa602a6bc8651a60a93 Author: Jason Merrill Date: Tue May 15 15:46:51 2018 -0400 PR c++/64372 - CWG 1560, gratuitous lvalue-rvalue conversion in ?: * call.c (build_conditional_expr_1): Don't force_rvalue when one arm is a throw-expression. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index f620c0d86e8..09a3618b007 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -4969,56 +4969,33 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, arg3_type = unlowered_expr_type (arg3); if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type)) { - /* Do the conversions. We don't these for `void' type arguments - since it can't have any effect and since decay_conversion - does not handle that case gracefully. */ - if (!VOID_TYPE_P (arg2_type)) - arg2 = decay_conversion (arg2, complain); - if (!VOID_TYPE_P (arg3_type)) - arg3 = decay_conversion (arg3, complain); - arg2_type = TREE_TYPE (arg2); - arg3_type = TREE_TYPE (arg3); - /* [expr.cond] One of the following shall hold: --The second or the third operand (but not both) is a - throw-expression (_except.throw_); the result is of the - type of the other and is an rvalue. + throw-expression (_except.throw_); the result is of the type + and value category of the other. --Both the second and the third operands have type void; the - result is of type void and is an rvalue. - - We must avoid calling force_rvalue for expressions of type - "void" because it will complain that their value is being - used. */ + result is of type void and is a prvalue. */ if (TREE_CODE (arg2) == THROW_EXPR && TREE_CODE (arg3) != THROW_EXPR) { - if (!VOID_TYPE_P (arg3_type)) - { - arg3 = force_rvalue (arg3, complain); - if (arg3 == error_mark_node) - return error_mark_node; - } - arg3_type = TREE_TYPE (arg3); result_type = arg3_type; + is_glvalue = glvalue_p (arg3); } else if (TREE_CODE (arg2) != THROW_EXPR && TREE_CODE (arg3) == THROW_EXPR) { - if (!VOID_TYPE_P (arg2_type)) - { - arg2 = force_rvalue (arg2, complain); - if (arg2 == error_mark_node) - return error_mark_node; - } - arg2_type = TREE_TYPE (arg2); result_type = arg2_type; + is_glvalue = glvalue_p (arg2); } else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type)) - result_type = void_type_node; + { + result_type = void_type_node; + is_glvalue = false; + } else { if (complain & tf_error) @@ -5037,7 +5014,6 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, return error_mark_node; } - is_glvalue = false; goto valid_operands; } /* [expr.cond] @@ -5155,10 +5131,6 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, && same_type_p (arg2_type, arg3_type)) { result_type = arg2_type; - if (processing_template_decl) - /* Let lvalue_kind know this was a glvalue. */ - result_type = cp_build_reference_type (result_type, xvalue_p (arg2)); - arg2 = mark_lvalue_use (arg2); arg3 = mark_lvalue_use (arg3); goto valid_operands; @@ -5352,6 +5324,13 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3, return error_mark_node; valid_operands: + if (processing_template_decl && is_glvalue) + { + /* Let lvalue_kind know this was a glvalue. */ + tree arg = (result_type == arg2_type ? arg2 : arg3); + result_type = cp_build_reference_type (result_type, xvalue_p (arg)); + } + result = build3_loc (loc, COND_EXPR, result_type, arg1, arg2, arg3); /* If the ARG2 and ARG3 are the same and don't have side-effects, diff --git a/gcc/testsuite/g++.dg/cpp1y/dr1560.C b/gcc/testsuite/g++.dg/cpp1y/dr1560.C new file mode 100644 index 00000000000..b21ca98e279 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/dr1560.C @@ -0,0 +1,14 @@ +// Core 1560 +// { dg-do compile { target c++14 } } + +struct A +{ + A(); + A(const A&) = delete; +}; + +void f(bool b) +{ + A a; + b ? a : throw 42; +}