re PR c++/88103 (Wrong value category when conditional expression result is used...
authorJakub Jelinek <jakub@redhat.com>
Tue, 4 Dec 2018 08:44:12 +0000 (09:44 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Tue, 4 Dec 2018 08:44:12 +0000 (09:44 +0100)
PR c++/88103
* typeck.c (build_class_member_access_expr): If unary_complex_lvalue
turned xvalue_p into non-xvalue_p, call move on it.

* g++.dg/cpp0x/rv-cond3.C: New test.

From-SVN: r266772

gcc/cp/ChangeLog
gcc/cp/typeck.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/rv-cond3.C [new file with mode: 0644]

index 02f08ab..48f802b 100644 (file)
@@ -1,3 +1,9 @@
+2018-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/88103
+       * typeck.c (build_class_member_access_expr): If unary_complex_lvalue
+       turned xvalue_p into non-xvalue_p, call move on it.
+
 2018-12-02  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/88258
index f45c06e..86c95d7 100644 (file)
@@ -2422,7 +2422,13 @@ build_class_member_access_expr (cp_expr object, tree member,
   {
     tree temp = unary_complex_lvalue (ADDR_EXPR, object);
     if (temp)
-      object = cp_build_fold_indirect_ref (temp);
+      {
+       temp = cp_build_fold_indirect_ref (temp);
+       if (xvalue_p (object) && !xvalue_p (temp))
+         /* Preserve xvalue kind.  */
+         temp = move (temp);
+       object = temp;
+      }
   }
 
   /* In [expr.ref], there is an explicit list of the valid choices for
index edd24f2..99a4443 100644 (file)
@@ -1,3 +1,8 @@
+2018-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/88103
+       * g++.dg/cpp0x/rv-cond3.C: New test.
+
 2018-12-04  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/88315
diff --git a/gcc/testsuite/g++.dg/cpp0x/rv-cond3.C b/gcc/testsuite/g++.dg/cpp0x/rv-cond3.C
new file mode 100644 (file)
index 0000000..74b010b
--- /dev/null
@@ -0,0 +1,22 @@
+// PR c++/88103
+// { dg-do compile { target c++11 } }
+
+struct A {
+  A (int);
+  A&& foo () &&;
+  int i;
+};
+void free (A&&);
+
+void test_xvalue (A a){
+  A&& ref = true ? static_cast<A&&> (a) : static_cast<A&&> (a); 
+  free (true ? static_cast<A&&> (a) : static_cast<A&&> (a));
+  (true ? static_cast<A&&> (a) : static_cast<A&&> (a)).foo ();
+  int&& k = (true ? static_cast<A&&> (a) : static_cast<A&&> (a)).i;
+}
+void test_prvalue (A a){
+  A&& ref = true ? static_cast<A&&> (a) : 1; 
+  free (true ? static_cast<A&&> (a) : 1);
+  (true ? static_cast<A&&> (a) : 1).foo ();
+  int&& k = (true ? static_cast<A&&> (a) : 1).i;
+}