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