[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / SemaCXX / ast-print.cpp
blob2cb1ec440b6bb37af202aab5f659c17c3491fa0d
1 // RUN: %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 | FileCheck %s
3 // CHECK: r;
4 // CHECK-NEXT: (r->method());
5 struct MyClass
7 void method() {}
8 };
10 struct Reference
12 MyClass* object;
13 MyClass* operator ->() { return object; }
16 void test1() {
17 Reference r;
18 (r->method());
21 // CHECK: if (int a = 1)
22 // CHECK: while (int a = 1)
23 // CHECK: switch (int a = 1)
24 // CHECK: for (; int a = 1;)
26 void test2()
28 if (int a = 1) { }
29 while (int a = 1) { }
30 switch (int a = 1) { }
31 for(; int a = 1; ) { }
34 // CHECK: new (1) int;
35 void *operator new (typeof(sizeof(1)), int, int = 2);
36 void test3() {
37 new (1) int;
40 // CHECK: new X;
41 struct X {
42 void *operator new (typeof(sizeof(1)), int = 2);
44 void test4() { new X; }
46 // CHECK: for (int i = 2097, j = 42; false;)
47 void test5() {
48 for (int i = 2097, j = 42; false;) {}
51 // CHECK: test6fn((int &)y);
52 void test6fn(int& x);
53 void test6() {
54 unsigned int y = 0;
55 test6fn((int&)y);
58 // CHECK: S s(1, 2);
60 template <class S> void test7()
62 S s( 1,2 );
66 // CHECK: t.~T();
68 template <typename T> void test8(T t) { t.~T(); }
71 // CHECK: enum E
72 // CHECK-NEXT: A,
73 // CHECK-NEXT: B,
74 // CHECK-NEXT: C
75 // CHECK-NEXT: };
76 // CHECK-NEXT: {{^[ ]+}}E a = A;
78 struct test9
80 void f()
82 enum E { A, B, C };
83 E a = A;
87 namespace test10 {
88 namespace M {
89 template<typename T>
90 struct X {
91 enum { value };
96 typedef int INT;
98 // CHECK: test11
99 // CHECK-NEXT: return test10::M::X<INT>::value;
100 int test11() {
101 return test10::M::X<INT>::value;
105 struct DefaultArgClass
107 DefaultArgClass(int a = 1) {}
108 DefaultArgClass(int a, int b, int c = 1) {}
111 struct NoArgClass
113 NoArgClass() {}
116 struct VirualDestrClass
118 VirualDestrClass(int arg);
119 virtual ~VirualDestrClass();
122 struct ConstrWithCleanupsClass
124 ConstrWithCleanupsClass(const VirualDestrClass& cplx = VirualDestrClass(42));
127 // CHECK: test12
128 // CHECK-NEXT: DefaultArgClass useDefaultArg;
129 // CHECK-NEXT: DefaultArgClass overrideDefaultArg(1);
130 // CHECK-NEXT: DefaultArgClass(1, 2);
131 // CHECK-NEXT: DefaultArgClass(1, 2, 3);
132 // CHECK-NEXT: NoArgClass noArg;
133 // CHECK-NEXT: ConstrWithCleanupsClass cwcNoArg;
134 // CHECK-NEXT: ConstrWithCleanupsClass cwcOverrideArg(48);
135 // CHECK-NEXT: ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
136 void test12() {
137 DefaultArgClass useDefaultArg;
138 DefaultArgClass overrideDefaultArg(1);
139 DefaultArgClass tempWithDefaultArg = DefaultArgClass(1, 2);
140 DefaultArgClass tempWithExplictArg = DefaultArgClass(1, 2, 3);
141 NoArgClass noArg;
142 ConstrWithCleanupsClass cwcNoArg;
143 ConstrWithCleanupsClass cwcOverrideArg(48);
144 ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
147 // CHECK: void test13() {
148 // CHECK: _Atomic(int) i;
149 // CHECK: __c11_atomic_init(&i, 0);
150 // CHECK: __c11_atomic_load(&i, 0);
151 // CHECK: }
152 void test13() {
153 _Atomic(int) i;
154 __c11_atomic_init(&i, 0);
155 __c11_atomic_load(&i, 0);
159 // CHECK: void test14() {
160 // CHECK: struct X {
161 // CHECK: union {
162 // CHECK: int x;
163 // CHECK: } x;
164 // CHECK: };
165 // CHECK: }
166 void test14() {
167 struct X { union { int x; } x; };
171 // CHECK: float test15() {
172 // CHECK: return __builtin_asinf(1.F);
173 // CHECK: }
174 // CHECK-NOT: extern "C"
175 float test15() {
176 return __builtin_asinf(1.0F);
179 namespace PR18776 {
180 struct A {
181 operator void *();
182 explicit operator bool();
183 A operator&(A);
186 // CHECK: struct A
187 // CHECK-NEXT: {{^[ ]*operator}} void *();
188 // CHECK-NEXT: {{^[ ]*explicit}} operator bool();
190 void bar(void *);
192 void foo() {
193 A a, b;
194 bar(a & b);
195 // CHECK: bar(a & b);
196 if (a & b)
197 // CHECK: if (a & b)
198 return;
202 namespace {
203 void test(int i) {
204 switch (i) {
205 case 1:
206 // CHECK: {{\[\[clang::fallthrough\]\]}}
207 [[clang::fallthrough]];
208 case 2:
209 break;
214 namespace {
215 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
216 struct [[gnu::visibility("hidden")]] S;
219 // CHECK: struct CXXFunctionalCastExprPrint {
220 // CHECK-NEXT: } fce = CXXFunctionalCastExprPrint{};
221 struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{};
223 // CHECK: struct CXXTemporaryObjectExprPrint {
224 // CHECK-NEXT: CXXTemporaryObjectExprPrint();
225 // CHECK-NEXT: } toe = CXXTemporaryObjectExprPrint{};
226 struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{};
228 namespace PR24872 {
229 // CHECK: template <typename T> struct Foo : T {
230 // CHECK: using T::operator-;
231 template <typename T> struct Foo : T {
232 using T::operator-;
236 namespace dont_crash_on_auto_vars {
237 struct T { enum E {X = 12ll }; };
238 struct S {
239 struct { int I; } ADecl;
240 static const auto Y = T::X;
242 //CHECK: static const auto Y = T::X;
243 constexpr auto var = T::X;
244 //CHECK: constexpr auto var = T::X;