diff mbox

Preserve xvalues in ?:

Message ID alpine.DEB.2.02.1307071552340.3286@stedding.saclay.inria.fr
State New
Headers show

Commit Message

Marc Glisse July 7, 2013, 2:02 p.m. UTC
Hello,

this patch gets us one line closer to implementing the proper C++11 
semantics for ?: (there are still quite a few missing).

Bootstrap+testsuite on x86_64-unknown-linux-gnu.

2013-07-07  Marc Glisse  <marc.glisse@inria.fr>

 	PR c++/53000
gcc/cp/
 	* call.c (build_conditional_expr_1): Preserve xvalues.

gcc/testsuite/
 	* g++.dg/cpp0x/decltype17.C: Adjust.

Comments

Jason Merrill July 8, 2013, 3:59 p.m. UTC | #1
OK.

Jason
diff mbox

Patch

Index: testsuite/g++.dg/cpp0x/decltype17.C
===================================================================
--- testsuite/g++.dg/cpp0x/decltype17.C	(revision 200742)
+++ testsuite/g++.dg/cpp0x/decltype17.C	(working copy)
@@ -17,13 +17,13 @@  decltype(true ? lvalueref() : lvalueref(
 
 decltype(true ? rvalueref() : rvalueref()) h()
 {}
 
 int main()
 {
   if (strcmp (typeid(f).name(), "FivE") != 0)
     return 1;
   if (strcmp (typeid(g).name(), "FRivE") != 0)
     return 2;
-  if (strcmp (typeid(h).name(), "FivE") != 0)
+  if (strcmp (typeid(h).name(), "FOivE") != 0)
     return 3;
 }
Index: cp/call.c
===================================================================
--- cp/call.c	(revision 200742)
+++ cp/call.c	(working copy)
@@ -4634,24 +4634,25 @@  build_conditional_expr_1 (location_t loc
 	  && CLASS_TYPE_P (arg2_type)
 	  && cp_type_quals (arg2_type) != cp_type_quals (arg3_type))
 	arg2_type = arg3_type =
 	  cp_build_qualified_type (arg2_type,
 				   cp_type_quals (arg2_type)
 				   | cp_type_quals (arg3_type));
     }
 
   /* [expr.cond]
 
-     If the second and third operands are lvalues and have the same
-     type, the result is of that type and is an lvalue.  */
-  if (real_lvalue_p (arg2)
-      && real_lvalue_p (arg3)
+     If the second and third operands are glvalues of the same value
+     category and have the same type, the result is of that type and
+     value category.  */
+  if (((real_lvalue_p (arg2) && real_lvalue_p (arg3))
+       || (xvalue_p (arg2) && xvalue_p (arg3)))
       && same_type_p (arg2_type, arg3_type))
     {
       result_type = arg2_type;
       arg2 = mark_lvalue_use (arg2);
       arg3 = mark_lvalue_use (arg3);
       goto valid_operands;
     }
 
   /* [expr.cond]