1 // RUN: %clang_cc1 -ast-print %s | FileCheck %s
2
3 // CHECK: r;
4 // CHECK-NEXT: (r->method());
5 struct MyClass
6 {
methodMyClass7 void method() {}
8 };
9
10 struct Reference
11 {
12 MyClass* object;
operator ->Reference13 MyClass* operator ->() { return object; }
14 };
15
test1()16 void test1() {
17 Reference r;
18 (r->method());
19 }
20
21 // CHECK: if (int a = 1)
22 // CHECK: while (int a = 1)
23 // CHECK: switch (int a = 1)
24
test2()25 void test2()
26 {
27 if (int a = 1) { }
28 while (int a = 1) { }
29 switch (int a = 1) { }
30 }
31
32 // CHECK: new (1) int;
33 void *operator new (typeof(sizeof(1)), int, int = 2);
test3()34 void test3() {
35 new (1) int;
36 }
37
38 // CHECK: new X;
39 struct X {
40 void *operator new (typeof(sizeof(1)), int = 2);
41 };
test4()42 void test4() { new X; }
43
44 // CHECK: for (int i = 2097, j = 42; false;)
test5()45 void test5() {
46 for (int i = 2097, j = 42; false;) {}
47 }
48
49 // CHECK: test6fn((int &)y);
50 void test6fn(int& x);
test6()51 void test6() {
52 unsigned int y = 0;
53 test6fn((int&)y);
54 }
55
56 // CHECK: S s( 1, 2 );
57
test7()58 template <class S> void test7()
59 {
60 S s( 1,2 );
61 }
62
63
64 // CHECK: t.~T();
65
test8(T t)66 template <typename T> void test8(T t) { t.~T(); }
67
68
69 // CHECK: enum E {
70 // CHECK-NEXT: A,
71 // CHECK-NEXT: B,
72 // CHECK-NEXT: C
73 // CHECK-NEXT: };
74 // CHECK-NEXT: {{^[ ]+}}E a = A;
75
76 struct test9
77 {
ftest978 void f()
79 {
80 enum E { A, B, C };
81 E a = A;
82 }
83 };
84
85 namespace test10 {
86 namespace M {
87 template<typename T>
88 struct X {
89 enum { value };
90 };
91 }
92 }
93
94 typedef int INT;
95
96 // CHECK: test11
97 // CHECK-NEXT: return test10::M::X<INT>::value;
test11()98 int test11() {
99 return test10::M::X<INT>::value;
100 }
101
102
103 struct DefaultArgClass
104 {
DefaultArgClassDefaultArgClass105 DefaultArgClass(int a = 1) {}
DefaultArgClassDefaultArgClass106 DefaultArgClass(int a, int b, int c = 1) {}
107 };
108
109 struct NoArgClass
110 {
NoArgClassNoArgClass111 NoArgClass() {}
112 };
113
114 struct VirualDestrClass
115 {
116 VirualDestrClass(int arg);
117 virtual ~VirualDestrClass();
118 };
119
120 struct ConstrWithCleanupsClass
121 {
122 ConstrWithCleanupsClass(const VirualDestrClass& cplx = VirualDestrClass(42));
123 };
124
125 // CHECK: test12
126 // CHECK-NEXT: DefaultArgClass useDefaultArg;
127 // CHECK-NEXT: DefaultArgClass overrideDefaultArg(1);
128 // CHECK-NEXT: DefaultArgClass(1, 2);
129 // CHECK-NEXT: DefaultArgClass(1, 2, 3);
130 // CHECK-NEXT: NoArgClass noArg;
131 // CHECK-NEXT: ConstrWithCleanupsClass cwcNoArg;
132 // CHECK-NEXT: ConstrWithCleanupsClass cwcOverrideArg(48);
133 // CHECK-NEXT: ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
test12()134 void test12() {
135 DefaultArgClass useDefaultArg;
136 DefaultArgClass overrideDefaultArg(1);
137 DefaultArgClass tempWithDefaultArg = DefaultArgClass(1, 2);
138 DefaultArgClass tempWithExplictArg = DefaultArgClass(1, 2, 3);
139 NoArgClass noArg;
140 ConstrWithCleanupsClass cwcNoArg;
141 ConstrWithCleanupsClass cwcOverrideArg(48);
142 ConstrWithCleanupsClass cwcExplicitArg(VirualDestrClass(56));
143 }
144
145 // CHECK: void test13() {
146 // CHECK: _Atomic(int) i;
147 // CHECK: __c11_atomic_init(&i, 0);
148 // CHECK: __c11_atomic_load(&i, 0);
149 // CHECK: }
test13()150 void test13() {
151 _Atomic(int) i;
152 __c11_atomic_init(&i, 0);
153 __c11_atomic_load(&i, 0);
154 }
155
156