xref: /aosp_15_r20/external/clang/test/Misc/ast-dump-stmt.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -fcxx-exceptions -ast-dump -ast-dump-filter Test %s | FileCheck -strict-whitespace %s
2*67e74705SXin Li 
3*67e74705SXin Li namespace n {
function()4*67e74705SXin Li void function() {}
5*67e74705SXin Li int Variable;
6*67e74705SXin Li }
7*67e74705SXin Li using n::function;
8*67e74705SXin Li using n::Variable;
TestFunction()9*67e74705SXin Li void TestFunction() {
10*67e74705SXin Li   void (*f)() = &function;
11*67e74705SXin Li // CHECK:       DeclRefExpr{{.*}} (UsingShadow{{.*}}function
12*67e74705SXin Li   Variable = 4;
13*67e74705SXin Li // CHECK:       DeclRefExpr{{.*}} (UsingShadow{{.*}}Variable
14*67e74705SXin Li }
15*67e74705SXin Li 
16*67e74705SXin Li // CHECK: FunctionDecl {{.*}} TestCatch1
TestCatch1()17*67e74705SXin Li void TestCatch1() {
18*67e74705SXin Li // CHECK:       CXXTryStmt
19*67e74705SXin Li // CHECK-NEXT:    CompoundStmt
20*67e74705SXin Li   try {
21*67e74705SXin Li   }
22*67e74705SXin Li // CHECK-NEXT:    CXXCatchStmt
23*67e74705SXin Li // CHECK-NEXT:      VarDecl {{.*}} x
24*67e74705SXin Li // CHECK-NEXT:      CompoundStmt
25*67e74705SXin Li   catch (int x) {
26*67e74705SXin Li   }
27*67e74705SXin Li }
28*67e74705SXin Li 
29*67e74705SXin Li // CHECK: FunctionDecl {{.*}} TestCatch2
TestCatch2()30*67e74705SXin Li void TestCatch2() {
31*67e74705SXin Li // CHECK:       CXXTryStmt
32*67e74705SXin Li // CHECK-NEXT:    CompoundStmt
33*67e74705SXin Li   try {
34*67e74705SXin Li   }
35*67e74705SXin Li // CHECK-NEXT:    CXXCatchStmt
36*67e74705SXin Li // CHECK-NEXT:      NULL
37*67e74705SXin Li // CHECK-NEXT:      CompoundStmt
38*67e74705SXin Li   catch (...) {
39*67e74705SXin Li   }
40*67e74705SXin Li }
41*67e74705SXin Li 
TestAllocationExprs()42*67e74705SXin Li void TestAllocationExprs() {
43*67e74705SXin Li   int *p;
44*67e74705SXin Li   p = new int;
45*67e74705SXin Li   delete p;
46*67e74705SXin Li   p = new int[2];
47*67e74705SXin Li   delete[] p;
48*67e74705SXin Li   p = ::new int;
49*67e74705SXin Li   ::delete p;
50*67e74705SXin Li }
51*67e74705SXin Li // CHECK: FunctionDecl {{.*}} TestAllocationExprs
52*67e74705SXin Li // CHECK: CXXNewExpr {{.*}} 'int *' Function {{.*}} 'operator new'
53*67e74705SXin Li // CHECK: CXXDeleteExpr {{.*}} 'void' Function {{.*}} 'operator delete'
54*67e74705SXin Li // CHECK: CXXNewExpr {{.*}} 'int *' array Function {{.*}} 'operator new[]'
55*67e74705SXin Li // CHECK: CXXDeleteExpr {{.*}} 'void' array Function {{.*}} 'operator delete[]'
56*67e74705SXin Li // CHECK: CXXNewExpr {{.*}} 'int *' global Function {{.*}} 'operator new'
57*67e74705SXin Li // CHECK: CXXDeleteExpr {{.*}} 'void' global Function {{.*}} 'operator delete'
58*67e74705SXin Li 
59*67e74705SXin Li // Don't crash on dependent exprs that haven't been resolved yet.
60*67e74705SXin Li template <typename T>
TestDependentAllocationExpr()61*67e74705SXin Li void TestDependentAllocationExpr() {
62*67e74705SXin Li   T *p = new T;
63*67e74705SXin Li   delete p;
64*67e74705SXin Li }
65*67e74705SXin Li // CHECK: FunctionTemplateDecl {{.*}} TestDependentAllocationExpr
66*67e74705SXin Li // CHECK: CXXNewExpr {{.*'T \*'$}}
67*67e74705SXin Li // CHECK: CXXDeleteExpr {{.*'void'$}}
68