gcc/testsuite/g++.dg/contracts/contracts-nocopy1.C
raw| 1 | // Contracts shouldn't introduce more copies. |
| 2 | |
| 3 | // { dg-do compile { target c++20 } } |
| 4 | // { dg-additional-options -fcontracts } |
| 5 | |
| 6 | struct A |
| 7 | { |
| 8 | int i; |
| 9 | A(int i): i(i) { } |
| 10 | A(const A&) = delete; |
| 11 | }; |
| 12 | |
| 13 | A f(A a) |
| 14 | [[ pre: a.i > 0 ]] |
| 15 | [[ post r: r.i > 0 ]] |
| 16 | { |
| 17 | return {a.i}; |
| 18 | } |
| 19 | |
| 20 | int main() |
| 21 | { |
| 22 | if (f({42}).i != 42) |
| 23 | __builtin_abort (); |
| 24 | } |