1 // RUN: %clang_cc1 -triple %ms_abi_triple -ast-print %s -std=gnu++11 | FileCheck %s 2 3 // CHECK: r; 4 // CHECK-NEXT: (r->method()); 5 struct MyClass 6 { 7 void method() {} 8 }; 9 10 struct Reference 11 { 12 MyClass* object; 13 MyClass* operator ->() { return object; } 14 }; 15 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 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); 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 }; 42 void test4() { new X; } 43 44 // CHECK: for (int i = 2097, j = 42; false;) 45 void test5() { 46 for (int i = 2097, j = 42; false;) {} 47 } 48 49 // CHECK: test6fn((int &)y); 50 void test6fn(int& x); 51 void test6() { 52 unsigned int y = 0; 53 test6fn((int&)y); 54 } 55 56 // CHECK: S s(1, 2); 57 58 template <class S> void test7() 59 { 60 S s( 1,2 ); 61 } 62 63 64 // CHECK: t.~T(); 65 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 { 78 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; 98 int test11() { 99 return test10::M::X<INT>::value; 100 } 101 102 103 struct DefaultArgClass 104 { 105 DefaultArgClass(int a = 1) {} 106 DefaultArgClass(int a, int b, int c = 1) {} 107 }; 108 109 struct NoArgClass 110 { 111 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)); 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: } 150 void test13() { 151 _Atomic(int) i; 152 __c11_atomic_init(&i, 0); 153 __c11_atomic_load(&i, 0); 154 } 155 156 157 // CHECK: void test14() { 158 // CHECK: struct X { 159 // CHECK: union { 160 // CHECK: int x; 161 // CHECK: } x; 162 // CHECK: }; 163 // CHECK: } 164 void test14() { 165 struct X { union { int x; } x; }; 166 } 167 168 169 // CHECK: float test15() { 170 // CHECK: return __builtin_asinf(1.F); 171 // CHECK: } 172 // CHECK-NOT: extern "C" 173 float test15() { 174 return __builtin_asinf(1.0F); 175 } 176 177 namespace PR18776 { 178 struct A { 179 operator void *(); 180 explicit operator bool(); 181 A operator&(A); 182 }; 183 184 // CHECK: struct A 185 // CHECK-NEXT: {{^[ ]*operator}} void *(); 186 // CHECK-NEXT: {{^[ ]*explicit}} operator bool(); 187 188 void bar(void *); 189 190 void foo() { 191 A a, b; 192 bar(a & b); 193 // CHECK: bar(a & b); 194 if (a & b) 195 // CHECK: if (a & b) 196 return; 197 } 198 }; 199 200 namespace { 201 void test(int i) { 202 switch (i) { 203 case 1: 204 // CHECK: {{\[\[clang::fallthrough\]\]}} 205 [[clang::fallthrough]]; 206 case 2: 207 break; 208 } 209 } 210 } 211 212 namespace { 213 // CHECK: struct {{\[\[gnu::visibility\(\"hidden\"\)\]\]}} S; 214 struct [[gnu::visibility("hidden")]] S; 215 } 216 217 // CHECK: struct CXXFunctionalCastExprPrint fce = CXXFunctionalCastExprPrint{}; 218 struct CXXFunctionalCastExprPrint {} fce = CXXFunctionalCastExprPrint{}; 219 220 // CHECK: struct CXXTemporaryObjectExprPrint toe = CXXTemporaryObjectExprPrint{}; 221 struct CXXTemporaryObjectExprPrint { CXXTemporaryObjectExprPrint(); } toe = CXXTemporaryObjectExprPrint{}; 222 223 namespace PR24872 { 224 // CHECK: template <typename T> struct Foo : T { 225 // CHECK: using T::operator-; 226 template <typename T> struct Foo : T { 227 using T::operator-; 228 }; 229 } 230