diff options
author | Jason Merrill <jason@redhat.com> | 2023-06-05 23:58:32 -0400 |
---|---|---|
committer | Jason Merrill <jason@redhat.com> | 2023-06-06 21:30:00 -0400 |
commit | 0fa9495553e0e0f4ceb764880b5bdd8ade197382 (patch) | |
tree | aca36cafd1f8dd500890baac785a45898ff9715d /gcc/testsuite/g++.dg | |
parent | 4fe84e2a4c0b600d2bc01f171b3b9dd1f4357208 (diff) | |
download | gcc-0fa9495553e0e0f4ceb764880b5bdd8ade197382.zip gcc-0fa9495553e0e0f4ceb764880b5bdd8ade197382.tar.gz gcc-0fa9495553e0e0f4ceb764880b5bdd8ade197382.tar.bz2 |
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.
Diffstat (limited to 'gcc/testsuite/g++.dg')
-rw-r--r-- | gcc/testsuite/g++.dg/contracts/contracts-post7.C | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/contracts/contracts-post7.C b/gcc/testsuite/g++.dg/contracts/contracts-post7.C new file mode 100644 index 0000000..1c33181 --- /dev/null +++ b/gcc/testsuite/g++.dg/contracts/contracts-post7.C @@ -0,0 +1,29 @@ +// { dg-do run } +// { dg-options "-std=c++2a -fcontracts" } + +#include <experimental/contract> + +using std::experimental::contract_violation; +void handle_contract_violation(const contract_violation &violation) +{ + __builtin_exit (0); +} + +struct A { + int i; + A(): i(42) {} + A(const A&); +}; + +A f() + [[ post r: r.i == 24 ]] +{ + A a; + return a; +} + +int main() +{ + f(); + return -1; +} |