gcc/testsuite/g++.dg/cpp2a/constinit9.C
raw| 1 | // PR c++/91360 - Implement C++20 P1143R2: constinit |
| 2 | // { dg-do run { target c++20 } } |
| 3 | // A run-time test. |
| 4 | |
| 5 | constexpr int foo (int x) { return x; } |
| 6 | constinit int b = foo(42); |
| 7 | |
| 8 | int |
| 9 | main () |
| 10 | { |
| 11 | if (b != 42) |
| 12 | __builtin_abort (); |
| 13 | // We can still modify 'b'. |
| 14 | b = 10; |
| 15 | if (b != 10) |
| 16 | __builtin_abort (); |
| 17 | |
| 18 | constinit static int s = foo(14); |
| 19 | if (s != 14) |
| 20 | __builtin_abort (); |
| 21 | s++; |
| 22 | if (s != 15) |
| 23 | __builtin_abort (); |
| 24 | } |