c++: fix class-valued ?: extension
commitbbdb5612f6661f2c64b0c0f1d2291cb59fde2b40
authorJason Merrill <jason@redhat.com>
Fri, 23 Sep 2022 13:07:22 +0000 (23 09:07 -0400)
committerJason Merrill <jason@redhat.com>
Thu, 29 Sep 2022 17:50:03 +0000 (29 13:50 -0400)
tree56b89b14d6a13be4d736ff80363a0ba9300ea9d1
parent32b2eb59fb904926eff77811e08766a8ae6804a7
c++: fix class-valued ?: extension

When the gimplifier encounters the same TARGET_EXPR twice, it evaluates
TARGET_EXPR_INITIAL the first time and clears it so that the later
evaluation is just the temporary.  With this testcase, using the extension
to treat an omitted middle operand as repeating the first operand, that led
to doing a bitwise copy of the S(1) temporary on return rather than properly
calling the copy constructor.

We can't use S(1) to initialize the return value here anyway, because we
need to materialize it into a temporary so we can convert it to bool and
determine which arm we're evaluating.  So let's just treat the middle
operand as an xvalue.

PR c++/93046

gcc/cp/ChangeLog:

* call.cc (build_conditional_expr): For a?:c extension, treat
a reused class prvalue as an xvalue.

gcc/testsuite/ChangeLog:

* g++.dg/ext/cond4.C: Add runtime test.
gcc/cp/call.cc
gcc/testsuite/g++.dg/ext/cond4.C