Patchwork C++ PATCH for c++/51318 (confusion with rvalue ?: in template)

login
register
mail settings
Submitter Jason Merrill
Date Dec. 8, 2011, 10:26 p.m.
Message ID <4EE139AF.9010904@redhat.com>
Download mbox | patch
Permalink /patch/130245/
State New
Headers show

Comments

Jason Merrill - Dec. 8, 2011, 10:26 p.m.
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.

Patch

commit 5812d63f059c71b570ab840bb0381c5f45c93443
Author: Jason Merrill <jason@redhat.com>
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<bool B, int = B ? e0 : e1> struct A {};
+
+template<typename T> struct B
+{
+  A<T::X> a;
+};