1*0a6a1f1dSLionel Sambuc // RUN: %clang_cc1 -ast-print %s -std=gnu++11 | FileCheck %s
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc // CHECK: r;
4f4a2713aSLionel Sambuc // CHECK-NEXT: (r->method());
5f4a2713aSLionel Sambuc struct MyClass
6f4a2713aSLionel Sambuc {
methodMyClass7f4a2713aSLionel Sambuc     void method() {}
8f4a2713aSLionel Sambuc };
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc struct Reference
11f4a2713aSLionel Sambuc {
12f4a2713aSLionel Sambuc     MyClass* object;
operator ->Reference13f4a2713aSLionel Sambuc     MyClass* operator ->() { return object; }
14f4a2713aSLionel Sambuc };
15f4a2713aSLionel Sambuc 
test1()16f4a2713aSLionel Sambuc void test1() {
17f4a2713aSLionel Sambuc     Reference r;
18f4a2713aSLionel Sambuc     (r->method());
19f4a2713aSLionel Sambuc }
20f4a2713aSLionel Sambuc 
21f4a2713aSLionel Sambuc // CHECK: if (int a = 1)
22f4a2713aSLionel Sambuc // CHECK:  while (int a = 1)
23f4a2713aSLionel Sambuc // CHECK:  switch (int a = 1)
24f4a2713aSLionel Sambuc 
test2()25f4a2713aSLionel Sambuc void test2()
26f4a2713aSLionel Sambuc {
27f4a2713aSLionel Sambuc     if (int a = 1) { }
28f4a2713aSLionel Sambuc     while (int a = 1) { }
29f4a2713aSLionel Sambuc     switch (int a = 1) { }
30f4a2713aSLionel Sambuc }
31f4a2713aSLionel Sambuc 
32f4a2713aSLionel Sambuc // CHECK: new (1) int;
33f4a2713aSLionel Sambuc void *operator new (typeof(sizeof(1)), int, int = 2);
test3()34f4a2713aSLionel Sambuc void test3() {
35f4a2713aSLionel Sambuc   new (1) int;
36f4a2713aSLionel Sambuc }
37f4a2713aSLionel Sambuc 
38f4a2713aSLionel Sambuc // CHECK: new X;
39f4a2713aSLionel Sambuc struct X {
40f4a2713aSLionel Sambuc   void *operator new (typeof(sizeof(1)), int = 2);
41f4a2713aSLionel Sambuc };
test4()42f4a2713aSLionel Sambuc void test4() { new X; }
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc // CHECK: for (int i = 2097, j = 42; false;)
test5()45f4a2713aSLionel Sambuc void test5() {
46f4a2713aSLionel Sambuc   for (int i = 2097, j = 42; false;) {}
47f4a2713aSLionel Sambuc }
48f4a2713aSLionel Sambuc 
49f4a2713aSLionel Sambuc // CHECK: test6fn((int &)y);
50f4a2713aSLionel Sambuc void test6fn(int& x);
test6()51f4a2713aSLionel Sambuc void test6() {
52f4a2713aSLionel Sambuc     unsigned int y = 0;
53f4a2713aSLionel Sambuc     test6fn((int&)y);
54f4a2713aSLionel Sambuc }
55f4a2713aSLionel Sambuc 
56f4a2713aSLionel Sambuc // CHECK: S s( 1, 2 );
57f4a2713aSLionel Sambuc 
test7()58f4a2713aSLionel Sambuc template <class S> void test7()
59f4a2713aSLionel Sambuc {
60f4a2713aSLionel Sambuc     S s( 1,2 );
61f4a2713aSLionel Sambuc }
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc 
64f4a2713aSLionel Sambuc // CHECK: t.~T();
65f4a2713aSLionel Sambuc 
test8(T t)66f4a2713aSLionel Sambuc template <typename T> void test8(T t) { t.~T(); }
67f4a2713aSLionel Sambuc 
68f4a2713aSLionel Sambuc 
69f4a2713aSLionel Sambuc // CHECK:      enum E {
70f4a2713aSLionel Sambuc // CHECK-NEXT:  A,
71f4a2713aSLionel Sambuc // CHECK-NEXT:  B,
72f4a2713aSLionel Sambuc // CHECK-NEXT:  C
73f4a2713aSLionel Sambuc // CHECK-NEXT:  };
74f4a2713aSLionel Sambuc // CHECK-NEXT: {{^[ ]+}}E a = A;
75f4a2713aSLionel Sambuc 
76f4a2713aSLionel Sambuc struct test9
77f4a2713aSLionel Sambuc {
ftest978f4a2713aSLionel Sambuc     void f()
79f4a2713aSLionel Sambuc     {
80f4a2713aSLionel Sambuc         enum E { A, B, C };
81f4a2713aSLionel Sambuc         E a = A;
82f4a2713aSLionel Sambuc     }
83f4a2713aSLionel Sambuc };
84f4a2713aSLionel Sambuc 
85f4a2713aSLionel Sambuc namespace test10 {
86f4a2713aSLionel Sambuc   namespace M {
87f4a2713aSLionel Sambuc     template<typename T>
88f4a2713aSLionel Sambuc     struct X {
89f4a2713aSLionel Sambuc       enum { value };
90f4a2713aSLionel Sambuc     };
91f4a2713aSLionel Sambuc   }
92f4a2713aSLionel Sambuc }
93f4a2713aSLionel Sambuc 
94f4a2713aSLionel Sambuc typedef int INT;
95f4a2713aSLionel Sambuc 
96f4a2713aSLionel Sambuc // CHECK: test11
97f4a2713aSLionel Sambuc // CHECK-NEXT: return test10::M::X<INT>::value;
test11()98f4a2713aSLionel Sambuc int test11() {
99f4a2713aSLionel Sambuc   return test10::M::X<INT>::value;
100f4a2713aSLionel Sambuc }
101f4a2713aSLionel Sambuc 
102f4a2713aSLionel Sambuc 
103f4a2713aSLionel Sambuc struct DefaultArgClass
104f4a2713aSLionel Sambuc {
DefaultArgClassDefaultArgClass105f4a2713aSLionel Sambuc   DefaultArgClass(int a = 1) {}
DefaultArgClassDefaultArgClass106f4a2713aSLionel Sambuc   DefaultArgClass(int a, int b, int c = 1) {}
107f4a2713aSLionel Sambuc };
108f4a2713aSLionel Sambuc 
109f4a2713aSLionel Sambuc struct NoArgClass
110f4a2713aSLionel Sambuc {
NoArgClassNoArgClass111f4a2713aSLionel Sambuc   NoArgClass() {}
112f4a2713aSLionel Sambuc };
113f4a2713aSLionel Sambuc 
114f4a2713aSLionel Sambuc struct VirualDestrClass
115f4a2713aSLionel Sambuc {
116f4a2713aSLionel Sambuc   VirualDestrClass(int arg);
117f4a2713aSLionel Sambuc   virtual ~VirualDestrClass();
118f4a2713aSLionel Sambuc };
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc struct ConstrWithCleanupsClass
121f4a2713aSLionel Sambuc {
122f4a2713aSLionel Sambuc   ConstrWithCleanupsClass(const VirualDestrClass& cplx = VirualDestrClass(42));
123f4a2713aSLionel Sambuc };
124f4a2713aSLionel Sambuc 
125f4a2713aSLionel Sambuc // CHECK: test12
126f4a2713aSLionel Sambuc // CHECK-NEXT: DefaultArgClass useDefaultArg;
127f4a2713aSLionel Sambuc // CHECK-NEXT: DefaultArgClass overrideDefaultArg(1);
128f4a2713aSLionel Sambuc // CHECK-NEXT: DefaultArgClass(1, 2);
129f4a2713aSLionel Sambuc // CHECK-NEXT: DefaultArgClass(1, 2, 3);
130f4a2713aSLionel Sambuc // CHECK-NEXT: NoArgClass noArg;
131f4a2713aSLionel Sambuc // CHECK-NEXT: ConstrWithCleanupsClass cwcNoArg;
132f4a2713aSLionel Sambuc // CHECK-NEXT: ConstrWithCleanupsClass cwcOverrideArg(48);
133f4a2713aSLionel Sambuc // CHECK-NEXT: ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
test12()134f4a2713aSLionel Sambuc void test12() {
135f4a2713aSLionel Sambuc   DefaultArgClass useDefaultArg;
136f4a2713aSLionel Sambuc   DefaultArgClass overrideDefaultArg(1);
137f4a2713aSLionel Sambuc   DefaultArgClass tempWithDefaultArg = DefaultArgClass(1, 2);
138f4a2713aSLionel Sambuc   DefaultArgClass tempWithExplictArg = DefaultArgClass(1, 2, 3);
139f4a2713aSLionel Sambuc   NoArgClass noArg;
140f4a2713aSLionel Sambuc   ConstrWithCleanupsClass cwcNoArg;
141f4a2713aSLionel Sambuc   ConstrWithCleanupsClass cwcOverrideArg(48);
142f4a2713aSLionel Sambuc   ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
143f4a2713aSLionel Sambuc }
144f4a2713aSLionel Sambuc 
145f4a2713aSLionel Sambuc // CHECK: void test13() {
146f4a2713aSLionel Sambuc // CHECK:   _Atomic(int) i;
147f4a2713aSLionel Sambuc // CHECK:   __c11_atomic_init(&i, 0);
148f4a2713aSLionel Sambuc // CHECK:   __c11_atomic_load(&i, 0);
149f4a2713aSLionel Sambuc // CHECK: }
test13()150f4a2713aSLionel Sambuc void test13() {
151f4a2713aSLionel Sambuc   _Atomic(int) i;
152f4a2713aSLionel Sambuc   __c11_atomic_init(&i, 0);
153f4a2713aSLionel Sambuc   __c11_atomic_load(&i, 0);
154f4a2713aSLionel Sambuc }
155f4a2713aSLionel Sambuc 
156f4a2713aSLionel Sambuc 
157f4a2713aSLionel Sambuc // CHECK: void test14() {
158f4a2713aSLionel Sambuc // CHECK:     struct X {
159f4a2713aSLionel Sambuc // CHECK:         union {
160f4a2713aSLionel Sambuc // CHECK:             int x;
161f4a2713aSLionel Sambuc // CHECK:         } x;
162f4a2713aSLionel Sambuc // CHECK:     };
163f4a2713aSLionel Sambuc // CHECK: }
test14()164f4a2713aSLionel Sambuc void test14() {
165f4a2713aSLionel Sambuc   struct X { union { int x; } x; };
166f4a2713aSLionel Sambuc }
167*0a6a1f1dSLionel Sambuc 
168*0a6a1f1dSLionel Sambuc 
169*0a6a1f1dSLionel Sambuc // CHECK: float test15() {
170*0a6a1f1dSLionel Sambuc // CHECK:     return __builtin_asinf(1.F);
171*0a6a1f1dSLionel Sambuc // CHECK: }
172*0a6a1f1dSLionel Sambuc // CHECK-NOT: extern "C"
test15()173*0a6a1f1dSLionel Sambuc float test15() {
174*0a6a1f1dSLionel Sambuc   return __builtin_asinf(1.0F);
175*0a6a1f1dSLionel Sambuc }
176*0a6a1f1dSLionel Sambuc 
177*0a6a1f1dSLionel Sambuc namespace PR18776 {
178*0a6a1f1dSLionel Sambuc struct A {
179*0a6a1f1dSLionel Sambuc   operator void *();
180*0a6a1f1dSLionel Sambuc   explicit operator bool();
181*0a6a1f1dSLionel Sambuc   A operator&(A);
182*0a6a1f1dSLionel Sambuc };
183*0a6a1f1dSLionel Sambuc 
184*0a6a1f1dSLionel Sambuc // CHECK: struct A
185*0a6a1f1dSLionel Sambuc // CHECK-NEXT: {{^[ ]*operator}} void *();
186*0a6a1f1dSLionel Sambuc // CHECK-NEXT: {{^[ ]*explicit}} operator bool();
187*0a6a1f1dSLionel Sambuc 
188*0a6a1f1dSLionel Sambuc void bar(void *);
189*0a6a1f1dSLionel Sambuc 
foo()190*0a6a1f1dSLionel Sambuc void foo() {
191*0a6a1f1dSLionel Sambuc   A a, b;
192*0a6a1f1dSLionel Sambuc   bar(a & b);
193*0a6a1f1dSLionel Sambuc // CHECK: bar(a & b);
194*0a6a1f1dSLionel Sambuc   if (a & b)
195*0a6a1f1dSLionel Sambuc // CHECK: if (a & b)
196*0a6a1f1dSLionel Sambuc     return;
197*0a6a1f1dSLionel Sambuc }
198*0a6a1f1dSLionel Sambuc };
199*0a6a1f1dSLionel Sambuc 
200*0a6a1f1dSLionel Sambuc namespace {
test(int i)201*0a6a1f1dSLionel Sambuc void test(int i) {
202*0a6a1f1dSLionel Sambuc   switch (i) {
203*0a6a1f1dSLionel Sambuc     case 1:
204*0a6a1f1dSLionel Sambuc       // CHECK: {{\[\[clang::fallthrough\]\]}}
205*0a6a1f1dSLionel Sambuc       [[clang::fallthrough]];
206*0a6a1f1dSLionel Sambuc     case 2:
207*0a6a1f1dSLionel Sambuc       break;
208*0a6a1f1dSLionel Sambuc   }
209*0a6a1f1dSLionel Sambuc }
210*0a6a1f1dSLionel Sambuc }
211*0a6a1f1dSLionel Sambuc 
212*0a6a1f1dSLionel Sambuc namespace {
213*0a6a1f1dSLionel Sambuc // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S;
214*0a6a1f1dSLionel Sambuc struct [[gnu::visibility("hidden")]] S;
215*0a6a1f1dSLionel Sambuc }
216