]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: fix missing lifetime extension [PR119383]
authorMarek Polacek <polacek@redhat.com>
Tue, 25 Mar 2025 17:36:24 +0000 (13:36 -0400)
committerMarek Polacek <polacek@redhat.com>
Tue, 1 Apr 2025 12:36:49 +0000 (08:36 -0400)
commite9803f10c9f376f6d091e7ef3ad6e1c92e7c8e8c
tree6d7806246e420b305b1ab1b0e3719a06e590f55c
parent182d891e13c78187f5e4f76512e03297fea0e56a
c++: fix missing lifetime extension [PR119383]

Since r15-8011 cp_build_indirect_ref_1 won't do the *&TARGET_EXPR ->
TARGET_EXPR folding not to change its value category.  That fix seems
correct but it made us stop extending the lifetime in this testcase,
causing a wrong-code issue -- extend_ref_init_temps_1 did not see
through the extra *& because it doesn't use a tree walk.

This patch reverts r15-8011 and instead handles the problem in
build_over_call by calling force_lvalue in the is_really_empty_class
case as well as in the general case.

PR c++/119383

gcc/cp/ChangeLog:

* call.cc (build_over_call): Use force_lvalue to ensure op= returns
an lvalue.
* cp-tree.h (force_lvalue): Declare.
* cvt.cc (force_lvalue): New.
* typeck.cc (cp_build_indirect_ref_1): Revert r15-8011.

gcc/testsuite/ChangeLog:

* g++.dg/cpp0x/temp-extend3.C: New test.

Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/call.cc
gcc/cp/cp-tree.h
gcc/cp/cvt.cc
gcc/cp/typeck.cc
gcc/testsuite/g++.dg/cpp0x/temp-extend3.C [new file with mode: 0644]