xref: /llvm-project/clang/test/FixIt/fixit-c++2a.cpp (revision c9ab1d890586bd8a6a194e6a37968538b80f81bd)
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   int b = 123; // expected-note {{add the 'constinit' specifier}}
20   extern constinit int b; // expected-error {{'constinit' specifier added after initialization of variable}}
21   // CHECK: {{^}}  extern int b;
22 
23   template<typename> struct X {
24     template<int> static constinit int n; // expected-note {{constinit}}
25   };
26   template<typename T> template<int N>
27   int X<T>::n = 123; // expected-error {{missing}}
28   // CHECK: {{^}}  constinit int X<T>::n = 123;
29 
30 #define ABSL_CONST_INIT [[clang::require_constant_initialization]]
31   extern constinit int c; // expected-note {{constinit}}
32   int c; // expected-error {{missing}}
33   // CHECK: {{^}}  ABSL_CONST_INIT int c;
34 
35 #define MY_CONST_INIT constinit
36   extern constinit int d; // expected-note {{constinit}}
37   int d; // expected-error {{missing}}
38   // CHECK: {{^}}  MY_CONST_INIT int d;
39 #undef MY_CONST_INIT
40 
41   extern constinit int e; // expected-note {{constinit}}
42   int e; // expected-error {{missing}}
43   // CHECK: {{^}}  ABSL_CONST_INIT int e;
44 #undef ABSL_CONST_INIT
45 }
46