]> gcc.gnu.org Git - gcc.git/commitdiff
backport: re PR c++/88103 (Wrong value category when conditional expression result...
authorJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 11:16:55 +0000 (13:16 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 30 Aug 2019 11:16:55 +0000 (13:16 +0200)
Backported from mainline
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.

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

From-SVN: r275074

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

index 881df4a89a69273012555c47df39eddfa487f74e..1c416bcb0b68a36330c71ce3846020cde583664f 100644 (file)
@@ -1,6 +1,12 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
-
        Backported from mainline
+       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-11-27  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/88181
index 0da2da1c30f287bbc0401b2468cecb0672eac293..3b30a1e5b195862f1a26966edc03e71f49473f48 100644 (file)
@@ -2362,7 +2362,13 @@ build_class_member_access_expr (cp_expr object, tree member,
   {
     tree temp = unary_complex_lvalue (ADDR_EXPR, object);
     if (temp)
-      object = cp_build_indirect_ref (temp, RO_NULL, complain);
+      {
+       temp = cp_build_indirect_ref (temp, RO_NULL, complain);
+       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 b6520ca6fa4ce2a5c505f824a6ef2a9e30d64eb8..079ea89feffa7f8a0c8fe0388f8e0f4424aca4a0 100644 (file)
@@ -1,6 +1,11 @@
 2019-08-30  Jakub Jelinek  <jakub@redhat.com>
-
        Backported from mainline
+       2018-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/88103
+       * g++.dg/cpp0x/rv-cond3.C: New test.
+
        2018-12-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR tree-optimization/71109
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;
+}
This page took 0.094316 seconds and 5 git commands to generate.