From: Jakub Jelinek Date: Fri, 30 Aug 2019 11:16:55 +0000 (+0200) Subject: backport: re PR c++/88103 (Wrong value category when conditional expression result... X-Git-Tag: releases/gcc-7.5.0~287 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14ffeb1c3773c55cc96d2f7f0cf7a3db56f53571;p=thirdparty%2Fgcc.git backport: re PR c++/88103 (Wrong value category when conditional expression result is used as object expression) Backported from mainline 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. * g++.dg/cpp0x/rv-cond3.C: New test. From-SVN: r275074 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 881df4a89a69..1c416bcb0b68 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,6 +1,12 @@ 2019-08-30 Jakub Jelinek - + Backported from mainline + 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-11-27 Jakub Jelinek PR c++/88181 diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 0da2da1c30f2..3b30a1e5b195 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b6520ca6fa4c..079ea89feffa 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2019-08-30 Jakub Jelinek - + Backported from mainline + 2018-12-04 Jakub Jelinek + + PR c++/88103 + * g++.dg/cpp0x/rv-cond3.C: New test. + 2018-12-03 Jakub Jelinek 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 index 000000000000..74b010b055c2 --- /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; +}