From patchwork Thu Dec 8 22:26:55 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: C++ PATCH for c++/51318 (confusion with rvalue ?: in template) Date: Thu, 08 Dec 2011 12:26:55 -0000 From: Jason Merrill X-Patchwork-Id: 130245 Message-Id: <4EE139AF.9010904@redhat.com> To: gcc-patches List 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; +};