From patchwork Thu Dec 8 22:26:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 130245 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 92FF21007D1 for ; Fri, 9 Dec 2011 09:27:14 +1100 (EST) Received: (qmail 19638 invoked by alias); 8 Dec 2011 22:27:11 -0000 Received: (qmail 19625 invoked by uid 22791); 8 Dec 2011 22:27:10 -0000 X-SWARE-Spam-Status: No, hits=-7.2 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, SPF_HELO_PASS, TW_CX X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 08 Dec 2011 22:26:57 +0000 Received: from int-mx12.intmail.prod.int.phx2.redhat.com (int-mx12.intmail.prod.int.phx2.redhat.com [10.5.11.25]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id pB8MQvgb016237 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Thu, 8 Dec 2011 17:26:57 -0500 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx12.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id pB8MQvKF017879 for ; Thu, 8 Dec 2011 17:26:57 -0500 Received: from [0.0.0.0] (ovpn-113-21.phx2.redhat.com [10.3.113.21]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id pB8MQuFu009773 for ; Thu, 8 Dec 2011 17:26:56 -0500 Message-ID: <4EE139AF.9010904@redhat.com> Date: Thu, 08 Dec 2011 17:26:55 -0500 From: Jason Merrill User-Agent: Mozilla/5.0 (X11; Linux i686; rv:8.0) Gecko/20111112 Thunderbird/8.0 MIME-Version: 1.0 To: gcc-patches List Subject: C++ PATCH for c++/51318 (confusion with rvalue ?: in template) 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 This was an unfortunate interaction between the two hunks of my patch for 50835; lvalue_kind started assuming lvalue in C++98 templates, and then build_x_conditional_expr saw that and tried to play reference games as a result. Fixed by only playing reference games in C++11 mode. Tested x86_64-pc-linux-gnu, applying to trunk. commit 5812d63f059c71b570ab840bb0381c5f45c93443 Author: Jason Merrill Date: Thu Dec 8 15:46:57 2011 -0500 PR c++/51318 * typeck.c (build_x_conditional_expr): Restrict glvalue games to C++11. diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 9a5365c..4973d7d 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -5517,8 +5517,10 @@ build_x_conditional_expr (tree ifexp, tree op1, tree op2, { tree min = build_min_non_dep (COND_EXPR, expr, orig_ifexp, orig_op1, orig_op2); - /* Remember that the result is an lvalue or xvalue. */ - if (lvalue_or_rvalue_with_address_p (expr) + /* In C++11, remember that the result is an lvalue or xvalue. + In C++98, lvalue_kind can just assume lvalue in a template. */ + if (cxx_dialect >= cxx0x + && lvalue_or_rvalue_with_address_p (expr) && !lvalue_or_rvalue_with_address_p (min)) TREE_TYPE (min) = cp_build_reference_type (TREE_TYPE (min), !real_lvalue_p (expr)); diff --git a/gcc/testsuite/g++.dg/template/cond8.C b/gcc/testsuite/g++.dg/template/cond8.C new file mode 100644 index 0000000..a3bad7e --- /dev/null +++ b/gcc/testsuite/g++.dg/template/cond8.C @@ -0,0 +1,10 @@ +// PR c++/51318 + +enum { e0, e1 }; + +template struct A {}; + +template struct B +{ + A a; +};