aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/constinit9.C
blob: 9c5c848f7fcb1a7824a5db1e181c8e64b526fcc2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// PR c++/91360 - Implement C++20 P1143R2: constinit
// { dg-do run { target c++20 } }
// A run-time test.

constexpr int foo (int x) { return x; }
constinit int b = foo(42);

int
main ()
{
  if (b != 42)
    __builtin_abort ();
  // We can still modify 'b'.
  b = 10;
  if (b != 10)
    __builtin_abort ();

  constinit static int s = foo(14);
  if (s != 14)
    __builtin_abort ();
  s++;
  if (s != 15)
    __builtin_abort ();
}