c++: fix contracts with NRV
commit0fa9495553e0e0f4ceb764880b5bdd8ade197382
authorJason Merrill <jason@redhat.com>
Tue, 6 Jun 2023 03:58:32 +0000 (5 23:58 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 7 Jun 2023 01:30:00 +0000 (6 21:30 -0400)
treeaca36cafd1f8dd500890baac785a45898ff9715d
parent4fe84e2a4c0b600d2bc01f171b3b9dd1f4357208
c++: fix contracts with NRV

The NRV implementation was blindly replacing the operand of RETURN_EXPR,
clobbering anything that check_return_expr might have added on to the actual
initialization, such as checking the postcondition.

gcc/cp/ChangeLog:

* semantics.cc (finalize_nrv_r): [RETURN_EXPR]: Only replace the
INIT_EXPR.

gcc/testsuite/ChangeLog:

* g++.dg/contracts/contracts-post7.C: New test.
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/contracts/contracts-post7.C [new file with mode: 0644]