[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / AST / ast-dump-stmt.cpp
blob6a1b0d366eda6a4a752c9d8d0329ebbe6dd1cbe2
1 // Test without serialization:
2 // RUN: %clang_cc1 -std=c++2b -triple x86_64-linux-gnu -fcxx-exceptions -ast-dump %s \
3 // RUN: | FileCheck -strict-whitespace %s
4 //
5 // Test with serialization:
6 // RUN: %clang_cc1 -std=c++2b -triple x86_64-linux-gnu -fcxx-exceptions -emit-pch -o %t %s
7 // RUN: %clang_cc1 -x c++ -std=c++2b -triple x86_64-linux-gnu -fcxx-exceptions -include-pch %t -ast-dump-all /dev/null \
8 // RUN: | sed -e "s/ <undeserialized declarations>//" -e "s/ imported//" \
9 // RUN: | FileCheck -strict-whitespace %s
11 namespace n {
12 void function() {}
13 int Variable;
15 using n::function;
16 using n::Variable;
17 void TestFunction() {
18 void (*f)() = &function;
19 // CHECK: DeclRefExpr{{.*}} (UsingShadow{{.*}}function
20 Variable = 4;
21 // CHECK: DeclRefExpr{{.*}} (UsingShadow{{.*}}Variable
24 // CHECK: FunctionDecl {{.*}} TestCatch1
25 void TestCatch1() {
26 // CHECK: CXXTryStmt
27 // CHECK-NEXT: CompoundStmt
28 try {
30 // CHECK-NEXT: CXXCatchStmt
31 // CHECK-NEXT: VarDecl {{.*}} x
32 // CHECK-NEXT: CompoundStmt
33 catch (int x) {
37 // CHECK: FunctionDecl {{.*}} TestCatch2
38 void TestCatch2() {
39 // CHECK: CXXTryStmt
40 // CHECK-NEXT: CompoundStmt
41 try {
43 // CHECK-NEXT: CXXCatchStmt
44 // CHECK-NEXT: NULL
45 // CHECK-NEXT: CompoundStmt
46 catch (...) {
50 void TestAllocationExprs() {
51 int *p;
52 p = new int;
53 delete p;
54 p = new int[2];
55 delete[] p;
56 p = ::new int;
57 ::delete p;
59 // CHECK: FunctionDecl {{.*}} TestAllocationExprs
60 // CHECK: CXXNewExpr {{.*}} 'int *' Function {{.*}} 'operator new'
61 // CHECK: CXXDeleteExpr {{.*}} 'void' Function {{.*}} 'operator delete'
62 // CHECK: CXXNewExpr {{.*}} 'int *' array Function {{.*}} 'operator new[]'
63 // CHECK: CXXDeleteExpr {{.*}} 'void' array Function {{.*}} 'operator delete[]'
64 // CHECK: CXXNewExpr {{.*}} 'int *' global Function {{.*}} 'operator new'
65 // CHECK: CXXDeleteExpr {{.*}} 'void' global Function {{.*}} 'operator delete'
67 // Don't crash on dependent exprs that haven't been resolved yet.
68 template <typename T>
69 void TestDependentAllocationExpr() {
70 T *p = new T;
71 delete p;
73 // CHECK: FunctionTemplateDecl {{.*}} TestDependentAllocationExpr
74 // CHECK: CXXNewExpr {{.*'T \*'$}}
75 // CHECK: CXXDeleteExpr {{.*'void'$}}
77 template <typename T>
78 class DependentScopeMemberExprWrapper {
79 T member;
82 template <typename T>
83 void TestDependentScopeMemberExpr() {
84 DependentScopeMemberExprWrapper<T> obj;
85 obj.member = T();
86 (&obj)->member = T();
88 // CHECK: FunctionTemplateDecl {{.*}} TestDependentScopeMemberExpr
89 // CHECK: CXXDependentScopeMemberExpr {{.*}} lvalue .member
90 // CHECK: CXXDependentScopeMemberExpr {{.*}} lvalue ->member
92 union U {
93 int i;
94 long l;
97 void TestUnionInitList()
99 U us[3] = {1};
100 // CHECK: VarDecl {{.+}} <col:3, col:15> col:5 us 'U[3]' cinit
101 // CHECK-NEXT: `-InitListExpr {{.+}} <col:13, col:15> 'U[3]'
102 // CHECK-NEXT: |-array_filler: InitListExpr {{.+}} <col:15> 'U':'U' field Field {{.+}} 'i' 'int'
103 // CHECK-NEXT: `-InitListExpr {{.+}} <col:14> 'U':'U' field Field {{.+}} 'i' 'int'
104 // CHECK-NEXT: `-IntegerLiteral {{.+}} <col:14> 'int' 1
107 void TestSwitch(int i) {
108 switch (int a; i)
110 // CHECK: SwitchStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5> has_init
111 // CHECK-NEXT: DeclStmt
112 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:11, col:15> col:15 a 'int'
113 // CHECK-NEXT: ImplicitCastExpr
114 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:18> 'int' lvalue ParmVar 0x{{[^ ]*}} 'i' 'int'
115 // CHECK-NEXT: NullStmt
118 void TestIf(bool b) {
119 if (int i = 12; b)
121 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5> has_init
122 // CHECK-NEXT: DeclStmt
123 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:7, col:15> col:11 i 'int' cinit
124 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:15> 'int' 12
125 // CHECK-NEXT: ImplicitCastExpr
126 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:19> 'bool' lvalue ParmVar 0x{{[^ ]*}} 'b' 'bool'
127 // CHECK-NEXT: NullStmt
129 if constexpr (sizeof(b) == 1)
131 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
132 // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} <line:[[@LINE-3]]:17, col:30> 'bool'
133 // CHECK-NEXT: value: Int 1
134 // CHECK-NEXT: BinaryOperator
135 // CHECK-NEXT: UnaryExprOrTypeTraitExpr
136 // CHECK-NEXT: ParenExpr
137 // CHECK-NEXT: DeclRefExpr
138 // CHECK-NEXT: ImplicitCastExpr
139 // CHECK-NEXT: IntegerLiteral
140 // CHECK-NEXT: NullStmt
142 if constexpr (sizeof(b) == 1)
144 else
146 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-4]]:3, line:[[@LINE-1]]:5> has_else
147 // CHECK-NEXT: ConstantExpr 0x{{[^ ]*}} <line:[[@LINE-5]]:17, col:30> 'bool'
148 // CHECK-NEXT: value: Int 1
149 // CHECK-NEXT: BinaryOperator
150 // CHECK-NEXT: UnaryExprOrTypeTraitExpr
151 // CHECK-NEXT: ParenExpr
152 // CHECK-NEXT: DeclRefExpr
153 // CHECK-NEXT: ImplicitCastExpr
154 // CHECK-NEXT: IntegerLiteral
155 // CHECK-NEXT: NullStmt
156 // CHECK-NEXT: NullStmt
158 if consteval {}
159 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-1]]:3, col:17> consteval
160 // CHECK-NEXT: CompoundStmt
162 if ! consteval {}
163 else {}
164 // CHECK: IfStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:9> has_else !consteval
165 // CHECK-NEXT: CompoundStmt
166 // CHECK-NEXT: CompoundStmt
169 struct Container {
170 int *begin() const;
171 int *end() const;
174 void TestIteration() {
175 for (int i = 0; int j = i; ++i)
177 // CHECK: ForStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
178 // CHECK-NEXT: DeclStmt
179 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:16> col:12 used i 'int' cinit
180 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:16> 'int' 0
181 // CHECK-NEXT: DeclStmt
182 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:19, col:27> col:23 used j 'int' cinit
183 // CHECK-NEXT: ImplicitCastExpr
184 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:27> 'int' lvalue Var 0x{{[^ ]*}} 'i' 'int'
185 // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:23> 'bool' <IntegralToBoolean>
186 // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}} <col:23> 'int' <LValueToRValue>
187 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:23> 'int' lvalue Var 0x{{[^ ]*}} 'j' 'int'
188 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:30, col:32> 'int' lvalue prefix '++'
189 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:32> 'int' lvalue Var 0x{{[^ ]*}} 'i' 'int'
190 // CHECK-NEXT: NullStmt
192 int vals[10];
193 for (int v : vals)
195 // CHECK: CXXForRangeStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
196 // CHECK-NEXT: <<<NULL>>>
197 // CHECK-NEXT: DeclStmt
198 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:16> col:16 implicit used __range1 'int (&)[10]' cinit
199 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'int[10]' lvalue Var 0x{{[^ ]*}} 'vals' 'int[10]'
200 // CHECK-NEXT: DeclStmt
201 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14> col:14 implicit used __begin1 'int *':'int *' cinit
202 // CHECK-NEXT: ImplicitCastExpr
203 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
204 // CHECK-NEXT: DeclStmt
205 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14, col:16> col:14 implicit used __end1 'int *':'int *' cinit
206 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:14, col:16> 'int *' '+'
207 // CHECK-NEXT: ImplicitCastExpr
208 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
209 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:16> 'long' 10
210 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:14> 'bool' '!='
211 // CHECK-NEXT: ImplicitCastExpr
212 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
213 // CHECK-NEXT: ImplicitCastExpr
214 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__end1' 'int *':'int *'
215 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue prefix '++'
216 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
217 // CHECK-NEXT: DeclStmt
218 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:14> col:12 v 'int' cinit
219 // CHECK-NEXT: ImplicitCastExpr
220 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int' lvalue prefix '*' cannot overflow
221 // CHECK-NEXT: ImplicitCastExpr
222 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
223 // CHECK-NEXT: NullStmt
225 Container C;
226 for (int v : C)
228 // CHECK: CXXForRangeStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
229 // CHECK-NEXT: <<<NULL>>>
230 // CHECK-NEXT: DeclStmt
231 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:16> col:16 implicit used __range1 'Container &' cinit
232 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:16> 'Container':'Container' lvalue Var 0x{{[^ ]*}} 'C' 'Container':'Container'
233 // CHECK-NEXT: DeclStmt
234 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14> col:14 implicit used __begin1 'int *':'int *' cinit
235 // CHECK-NEXT: CXXMemberCallExpr 0x{{[^ ]*}} <col:14> 'int *'
236 // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:14> '<bound member function type>' .begin 0x{{[^ ]*}}
237 // CHECK-NEXT: ImplicitCastExpr
238 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'Container':'Container' lvalue Var 0x{{[^ ]*}} '__range1' 'Container &'
239 // CHECK-NEXT: DeclStmt
240 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:14> col:14 implicit used __end1 'int *':'int *' cinit
241 // CHECK-NEXT: CXXMemberCallExpr 0x{{[^ ]*}} <col:14> 'int *'
242 // CHECK-NEXT: MemberExpr 0x{{[^ ]*}} <col:14> '<bound member function type>' .end 0x{{[^ ]*}}
243 // CHECK-NEXT: ImplicitCastExpr
244 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'Container':'Container' lvalue Var 0x{{[^ ]*}} '__range1' 'Container &'
245 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:14> 'bool' '!='
246 // CHECK-NEXT: ImplicitCastExpr
247 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
248 // CHECK-NEXT: ImplicitCastExpr
249 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__end1' 'int *':'int *'
250 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue prefix '++'
251 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
252 // CHECK-NEXT: DeclStmt
253 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:14> col:12 v 'int' cinit
254 // CHECK-NEXT: ImplicitCastExpr
255 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:14> 'int' lvalue prefix '*' cannot overflow
256 // CHECK-NEXT: ImplicitCastExpr
257 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:14> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
258 // CHECK-NEXT: NullStmt
260 for (int a; int v : vals)
262 // CHECK: CXXForRangeStmt 0x{{[^ ]*}} <line:[[@LINE-2]]:3, line:[[@LINE-1]]:5>
263 // CHECK-NEXT: DeclStmt
264 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:8, col:12> col:12 a 'int'
265 // CHECK-NEXT: DeclStmt
266 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:23> col:23 implicit used __range1 'int (&)[10]' cinit
267 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:23> 'int[10]' lvalue Var 0x{{[^ ]*}} 'vals' 'int[10]'
268 // CHECK-NEXT: DeclStmt
269 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:21> col:21 implicit used __begin1 'int *':'int *' cinit
270 // CHECK-NEXT: ImplicitCastExpr
271 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
272 // CHECK-NEXT: DeclStmt
273 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:21, col:23> col:21 implicit used __end1 'int *':'int *' cinit
274 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:21, col:23> 'int *' '+'
275 // CHECK-NEXT: ImplicitCastExpr
276 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int[10]' lvalue Var 0x{{[^ ]*}} '__range1' 'int (&)[10]'
277 // CHECK-NEXT: IntegerLiteral 0x{{[^ ]*}} <col:23> 'long' 10
278 // CHECK-NEXT: BinaryOperator 0x{{[^ ]*}} <col:21> 'bool' '!='
279 // CHECK-NEXT: ImplicitCastExpr
280 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
281 // CHECK-NEXT: ImplicitCastExpr
282 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__end1' 'int *':'int *'
283 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:21> 'int *':'int *' lvalue prefix '++'
284 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
285 // CHECK-NEXT: DeclStmt
286 // CHECK-NEXT: VarDecl 0x{{[^ ]*}} <col:15, col:21> col:19 v 'int' cinit
287 // CHECK-NEXT: ImplicitCastExpr
288 // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}} <col:21> 'int' lvalue prefix '*' cannot overflow
289 // CHECK-NEXT: ImplicitCastExpr
290 // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}} <col:21> 'int *':'int *' lvalue Var 0x{{[^ ]*}} '__begin1' 'int *':'int *'
291 // CHECK-NEXT: NullStmt