[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / FixIt / fixit-c++2a.cpp
bloba21dd701ec743169772fd484199638023dd3fb25
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
7 /* This is a test of the various code modification hints that only
8 apply in C++2a. */
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}}
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;
23 template<typename> struct X {
24 template<int> static constinit int n; // expected-note {{constinit}}
26 template<typename T> template<int N>
27 int X<T>::n = 123; // expected-error {{missing}}
28 // CHECK: {{^}} constinit int X<T>::n = 123;
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;
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
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