aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/cpp2a/constinit5.C
blob: 951c6fe1852f8311cbddc267af49686273cb87c3 (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
25
26
27
// PR c++/91360 - Implement C++20 P1143R2: constinit
// { dg-do compile { target c++20 } }
// Check that we preserve DECL_DECLARED_CONSTINIT_P in duplicate_decls.

int gl = 42;

struct S {
  constinit static int m;
  constinit static int n;
  constinit static const int &r1;
  constinit static const int &r2;
};

int S::m = 42;
int nonconst;
constinit int S::n = nonconst; // { dg-error "variable .S::n. does not have a constant initializer" }
// { dg-error "not usable in a constant expression" "" { target *-*-* } .-1 }

const int &S::r1 = gl;
const int &S::r2 = 42;

struct T {
  constinit static thread_local const int &r1;
  constinit static thread_local const int &r2;
};
constinit thread_local const int &T::r1 = gl;
constinit thread_local const int &T::r2 = 42; // { dg-error "variable .T::r2. does not have a constant initializer|not a constant expression" }