1 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions 2 3 4 // ::type_info is predeclared with forward class declartion 5 void f(const type_info &a); 6 7 8 // Microsoft doesn't validate exception specification. 9 namespace microsoft_exception_spec { 10 11 void foo(); // expected-note {{previous declaration}} 12 void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}} 13 14 void r6() throw(...); // expected-note {{previous declaration}} 15 void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}} 16 17 struct Base { 18 virtual void f2(); 19 virtual void f3() throw(...); 20 }; 21 22 struct Derived : Base { 23 virtual void f2() throw(...); 24 virtual void f3(); 25 }; 26 27 class A { 28 virtual ~A() throw(); // expected-note {{overridden virtual function is here}} 29 }; 30 31 class B : public A { 32 virtual ~B(); // expected-warning {{exception specification of overriding function is more lax than base version}} 33 }; 34 35 } 36 37 // MSVC allows type definition in anonymous union and struct 38 struct A 39 { 40 union 41 { 42 int a; 43 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 44 { 45 int c; 46 } d; 47 48 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 49 { 50 int e; 51 int ee; 52 } f; 53 54 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 55 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 56 }; 57 58 struct 59 { 60 int a2; 61 62 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 63 { 64 int c2; 65 } d2; 66 67 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 68 { 69 int e2; 70 int ee2; 71 } f2; 72 73 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 74 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 75 }; 76 }; 77 78 // __stdcall handling 79 struct M { 80 int __stdcall addP(); 81 float __stdcall subtractP(); 82 }; 83 84 // __unaligned handling 85 typedef char __unaligned *aligned_type; 86 87 88 template<typename T> void h1(T (__stdcall M::* const )()) { } 89 90 void m1() { 91 h1<int>(&M::addP); 92 h1(&M::subtractP); 93 } 94 95 96 97 98 99 void f(long long); 100 void f(int); 101 102 int main() 103 { 104 // This is an ambiguous call in standard C++. 105 // This calls f(long long) in Microsoft mode because LL is always signed. 106 f(0xffffffffffffffffLL); 107 f(0xffffffffffffffffi64); 108 } 109 110 // Enumeration types with a fixed underlying type. 111 const int seventeen = 17; 112 typedef int Int; 113 114 struct X0 { 115 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}} 116 enum E1 : seventeen; 117 }; 118 119 enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}} 120 SomeValue = 0x100000000 121 }; 122 123 124 class AAA { 125 __declspec(dllimport) void f(void) { } 126 void f2(void); 127 }; 128 129 __declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}} 130 131 } 132 133 134 135 template <class T> 136 class BB { 137 public: 138 void f(int g = 10 ); // expected-note {{previous definition is here}} 139 }; 140 141 template <class T> 142 void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}} 143 144 145 146 extern void static_func(); 147 void static_func(); // expected-note {{previous declaration is here}} 148 149 150 static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}} 151 { 152 153 } 154 155 long function_prototype(int a); 156 long (*function_ptr)(int a); 157 158 void function_to_voidptr_conv() { 159 void *a1 = function_prototype; 160 void *a2 = &function_prototype; 161 void *a3 = function_ptr; 162 } 163 164 165 void pointer_to_integral_type_conv(char* ptr) { 166 char ch = (char)ptr; 167 short sh = (short)ptr; 168 ch = (char)ptr; 169 sh = (short)ptr; 170 } 171 172 173 namespace friend_as_a_forward_decl { 174 175 class A { 176 class Nested { 177 friend class B; 178 B* b; 179 }; 180 B* b; 181 }; 182 B* global_b; 183 184 185 void f() 186 { 187 class Local { 188 friend class Z; 189 Z* b; 190 }; 191 Z* b; 192 } 193 194 } 195 196 struct PR11150 { 197 class X { 198 virtual void f() = 0; 199 }; 200 201 int array[__is_abstract(X)? 1 : -1]; 202 }; 203 204 void f() { int __except = 0; } 205 206 void ::f(); // expected-warning{{extra qualification on member 'f'}} 207 208 class C { 209 C::C(); // expected-warning{{extra qualification on member 'C'}} 210 }; 211 212 struct StructWithProperty { 213 __declspec(property(get=GetV)) int V1; 214 __declspec(property(put=SetV)) int V2; 215 __declspec(property(get=GetV, put=SetV_NotExist)) int V3; 216 __declspec(property(get=GetV_NotExist, put=SetV)) int V4; 217 __declspec(property(get=GetV, put=SetV)) int V5; 218 219 int GetV() { return 123; } 220 void SetV(int i) {} 221 }; 222 void TestProperty() { 223 StructWithProperty sp; 224 int i = sp.V2; // expected-error{{no getter defined for property 'V2'}} 225 sp.V1 = 12; // expected-error{{no setter defined for property 'V1'}} 226 int j = sp.V4; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}} 227 sp.V3 = 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}} 228 int k = sp.V5; 229 sp.V5 = k++; 230 } 231 232 /* 4 tests for PseudoObject, begin */ 233 struct SP1 234 { 235 bool operator()() { return true; } 236 }; 237 struct SP2 238 { 239 __declspec(property(get=GetV)) SP1 V; 240 SP1 GetV() { return SP1(); } 241 }; 242 void TestSP2() { 243 SP2 sp2; 244 bool b = sp2.V(); 245 } 246 247 struct SP3 { 248 template <class T> 249 void f(T t) {} 250 }; 251 template <class T> 252 struct SP4 253 { 254 __declspec(property(get=GetV)) int V; 255 int GetV() { return 123; } 256 void f() { SP3 s2; s2.f(V); } 257 }; 258 void TestSP4() { 259 SP4<int> s; 260 s.f(); 261 } 262 263 template <class T> 264 struct SP5 265 { 266 __declspec(property(get=GetV)) T V; 267 int GetV() { return 123; } 268 void f() { int *p = new int[V]; } 269 }; 270 271 template <class T> 272 struct SP6 273 { 274 public: 275 __declspec(property(get=GetV)) T V; 276 T GetV() { return 123; } 277 void f() { int t = V; } 278 }; 279 void TestSP6() { 280 SP6<int> c; 281 c.f(); 282 } 283 /* 4 tests for PseudoObject, end */ 284 285 // Property access: explicit, implicit, with Qualifier 286 struct SP7 { 287 __declspec(property(get=GetV, put=SetV)) int V; 288 int GetV() { return 123; } 289 void SetV(int v) {} 290 291 void ImplicitAccess() { int i = V; V = i; } 292 void ExplicitAccess() { int i = this->V; this->V = i; } 293 }; 294 struct SP8: public SP7 { 295 void AccessWithQualifier() { int i = SP7::V; SP7::V = i; } 296 }; 297 298 // Property usage 299 template <class T> 300 struct SP9 { 301 __declspec(property(get=GetV, put=SetV)) T V; 302 T GetV() { return 0; } 303 void SetV(T v) {} 304 void f() { V = this->V; V < this->V; } 305 void g() { V++; } 306 void h() { V*=2; } 307 }; 308 struct SP10 { 309 SP10(int v) {} 310 bool operator<(const SP10& v) { return true; } 311 SP10 operator*(int v) { return *this; } 312 SP10 operator+(int v) { return *this; } 313 SP10& operator=(const SP10& v) { return *this; } 314 }; 315 void TestSP9() { 316 SP9<int> c; 317 int i = c.V; // Decl initializer 318 i = c.V; // Binary op operand 319 c.SetV(c.V); // CallExpr arg 320 int *p = new int[c.V + 1]; // Array size 321 p[c.V] = 1; // Array index 322 323 c.V = 123; // Setter 324 325 c.V++; // Unary op operand 326 c.V *= 2; // Unary op operand 327 328 SP9<int*> c2; 329 c2.V[0] = 123; // Array 330 331 SP9<SP10> c3; 332 c3.f(); // Overloaded binary op operand 333 c3.g(); // Overloaded incdec op operand 334 c3.h(); // Overloaded unary op operand 335 } 336