1 // RUN: %clang_cc1 -verify -std=c++2a -pedantic-errors %s
2 // RUN: cp %s %t
3 // RUN: not %clang_cc1 -x c++ -std=c++2a -fixit %t
4 // RUN: %clang_cc1 -Wall -pedantic-errors -x c++ -std=c++2a %t
5 // RUN: cat %t | FileCheck %s
6 
7 /* This is a test of the various code modification hints that only
8    apply in C++2a. */
init_capture_pack(T...a)9 template<typename ...T> void init_capture_pack(T ...a) {
10   [x... = a]{}; // expected-error {{must appear before the name}}
11   [x = a...]{}; // expected-error {{must appear before the name}}
12   [...&x = a]{}; // expected-error {{must appear before the name}}
13   [...a]{}; // expected-error {{must appear after the name}}
14   [&...a]{}; // expected-error {{must appear after the name}}
15   [...&a]{}; // expected-error {{must appear after the name}}
16 }
17 
18 namespace constinit_mismatch {
19   extern thread_local constinit int a; // expected-note {{declared constinit here}}
20   thread_local int a = 123; // expected-error {{'constinit' specifier missing on initializing declaration of 'a'}}
21   // CHECK: {{^}}  constinit thread_local int a = 123;
22 
23   int b = 123; // expected-note {{add the 'constinit' specifier}}
24   extern constinit int b; // expected-error {{'constinit' specifier added after initialization of variable}}
25   // CHECK: {{^}}  extern int b;
26 
27   template<typename> struct X {
28     template<int> static constinit int n; // expected-note {{constinit}}
29   };
30   template<typename T> template<int N>
31   int X<T>::n = 123; // expected-error {{missing}}
32   // CHECK: {{^}}  constinit int X<T>::n = 123;
33 
34 #define ABSL_CONST_INIT [[clang::require_constant_initialization]]
35   extern constinit int c; // expected-note {{constinit}}
36   int c; // expected-error {{missing}}
37   // CHECK: {{^}}  ABSL_CONST_INIT int c;
38 
39 #define MY_CONST_INIT constinit
40   extern constinit int d; // expected-note {{constinit}}
41   int d; // expected-error {{missing}}
42   // CHECK: {{^}}  MY_CONST_INIT int d;
43 #undef MY_CONST_INIT
44 
45   extern constinit int e; // expected-note {{constinit}}
46   int e; // expected-error {{missing}}
47   // CHECK: {{^}}  ABSL_CONST_INIT int e;
48 #undef ABSL_CONST_INIT
49 }
50