comparison gcc/testsuite/g++.dg/cpp2a/constinit5.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // PR c++/91360 - Implement C++20 P1143R2: constinit
2 // { dg-do compile { target c++2a } }
3 // Check that we preserve DECL_DECLARED_CONSTINIT_P in duplicate_decls.
4
5 int gl = 42;
6
7 struct S {
8 constinit static int m;
9 constinit static int n;
10 constinit static const int &r1;
11 constinit static const int &r2;
12 };
13
14 int S::m = 42;
15 int nonconst;
16 constinit int S::n = nonconst; // { dg-error "variable .S::n. does not have a constant initializer" }
17 // { dg-error "not usable in a constant expression" "" { target *-*-* } .-1 }
18
19 const int &S::r1 = gl;
20 const int &S::r2 = 42;
21
22 struct T {
23 constinit static thread_local const int &r1;
24 constinit static thread_local const int &r2;
25 };
26 constinit thread_local const int &T::r1 = gl;
27 constinit thread_local const int &T::r2 = 42; // { dg-error "variable .T::r2. does not have a constant initializer|not a constant expression" }