aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2018-12-04 09:44:12 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2018-12-04 09:44:12 +0100
commit580b8d9b540761e4df47d22fbfc9372396db8748 (patch)
treeae816e7bce27a5c49e457b707e062410154eb296 /gcc
parent056775650ac086fb069e00415bf262e22f7579c5 (diff)
downloadgcc-580b8d9b540761e4df47d22fbfc9372396db8748.zip
gcc-580b8d9b540761e4df47d22fbfc9372396db8748.tar.gz
gcc-580b8d9b540761e4df47d22fbfc9372396db8748.tar.bz2
re PR c++/88103 (Wrong value category when conditional expression result is used as object expression)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog6
-rw-r--r--gcc/cp/typeck.c8
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/rv-cond3.C22
4 files changed, 40 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 02f08ab..48f802b 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index f45c06e..86c95d7 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -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
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index edd24f2..99a4443 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..74b010b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/rv-cond3.C
@@ -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;
+}