From 580b8d9b540761e4df47d22fbfc9372396db8748 Mon Sep 17 00:00:00 2001 From: Jakub Jelinek Date: Tue, 4 Dec 2018 09:44:12 +0100 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/typeck.c | 8 +++++++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/cpp0x/rv-cond3.C | 22 ++++++++++++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/rv-cond3.C 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 + + 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 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 + + PR c++/88103 + * g++.dg/cpp0x/rv-cond3.C: New test. + 2018-12-04 Richard Biener 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) : static_cast (a); + free (true ? static_cast (a) : static_cast (a)); + (true ? static_cast (a) : static_cast (a)).foo (); + int&& k = (true ? static_cast (a) : static_cast (a)).i; +} +void test_prvalue (A a){ + A&& ref = true ? static_cast (a) : 1; + free (true ? static_cast (a) : 1); + (true ? static_cast (a) : 1).foo (); + int&& k = (true ? static_cast (a) : 1).i; +} -- 2.7.4