1 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions -DTEST1 2 // RUN: %clang_cc1 -std=c++98 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions -DTEST1 3 // RUN: %clang_cc1 -std=c++11 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions -DTEST1 4 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fexceptions -fcxx-exceptions -DTEST2 5 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -fms-compatibility -verify -DTEST3 6 7 #if TEST1 8 9 // MSVC allows type definition in anonymous union and struct 10 struct A 11 { 12 union 13 { 14 int a; 15 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 16 { 17 int c; 18 } d; 19 20 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 21 { 22 int e; 23 int ee; 24 } f; 25 26 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 27 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 28 }; 29 30 struct 31 { 32 int a2; 33 34 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 35 { 36 int c2; 37 } d2; 38 39 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 40 { 41 int e2; 42 int ee2; 43 } f2; 44 45 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 46 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 47 }; 48 }; 49 50 // __stdcall handling 51 struct M { 52 int __stdcall addP(); 53 float __stdcall subtractP(); 54 }; 55 56 // __unaligned handling 57 typedef char __unaligned *aligned_type; 58 typedef struct UnalignedTag { int f; } __unaligned *aligned_type2; 59 typedef char __unaligned aligned_type3; 60 61 struct aligned_type4 { 62 int i; 63 }; 64 65 __unaligned int aligned_type4::*p1_aligned_type4 = &aligned_type4::i; 66 int aligned_type4::* __unaligned p2_aligned_type4 = &aligned_type4::i; 67 __unaligned int aligned_type4::* __unaligned p3_aligned_type4 = &aligned_type4::i; 68 void (aligned_type4::*__unaligned p4_aligned_type4)(); 69 70 // Check that __unaligned qualifier can be used for overloading 71 void foo_unaligned(int *arg) {} 72 void foo_unaligned(__unaligned int *arg) {} 73 void foo_unaligned(int arg) {} // expected-note {{previous definition is here}} 74 void foo_unaligned(__unaligned int arg) {} // expected-error {{redefinition of 'foo_unaligned'}} 75 class A_unaligned {}; 76 class B_unaligned : public A_unaligned {}; 77 int foo_unaligned(__unaligned A_unaligned *arg) { return 0; } 78 void *foo_unaligned(B_unaligned *arg) { return 0; } 79 80 void test_unaligned() { 81 int *p1 = 0; 82 foo_unaligned(p1); 83 84 __unaligned int *p2 = 0; 85 foo_unaligned(p2); 86 87 __unaligned B_unaligned *p3 = 0; 88 int p4 = foo_unaligned(p3); 89 90 B_unaligned *p5 = p3; // expected-error {{cannot initialize a variable of type 'B_unaligned *' with an lvalue of type '__unaligned B_unaligned *'}} 91 92 __unaligned B_unaligned *p6 = p3; 93 94 p1_aligned_type4 = p2_aligned_type4; 95 p2_aligned_type4 = p1_aligned_type4; // expected-error {{assigning to 'int aligned_type4::*' from incompatible type '__unaligned int aligned_type4::*'}} 96 p3_aligned_type4 = p1_aligned_type4; 97 98 __unaligned int a[10]; 99 int *b = a; // expected-error {{cannot initialize a variable of type 'int *' with an lvalue of type '__unaligned int [10]'}} 100 } 101 102 // Test from PR27367 103 // We should accept assignment of an __unaligned pointer to a non-__unaligned 104 // pointer to void 105 typedef struct _ITEMIDLIST { int i; } ITEMIDLIST; 106 typedef ITEMIDLIST __unaligned *LPITEMIDLIST; 107 extern "C" __declspec(dllimport) void __stdcall CoTaskMemFree(void* pv); 108 __inline void FreeIDListArray(LPITEMIDLIST *ppidls) { 109 CoTaskMemFree(*ppidls); 110 __unaligned int *x = 0; 111 void *y = x; 112 } 113 114 // Test from PR27666 115 // We should accept type conversion of __unaligned to non-__unaligned references 116 typedef struct in_addr { 117 public: 118 in_addr(in_addr &a) {} // expected-note {{candidate constructor not viable: no known conversion from '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to 'in_addr &' for 1st argument; dereference the argument with *}} 119 in_addr(in_addr *a) {} // expected-note {{candidate constructor not viable: 1st argument ('__unaligned IN_ADDR *' (aka '__unaligned in_addr *')) would lose __unaligned qualifier}} 120 } IN_ADDR; 121 122 void f(IN_ADDR __unaligned *a) { 123 IN_ADDR local_addr = *a; 124 IN_ADDR local_addr2 = a; // expected-error {{no viable conversion from '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to 'IN_ADDR' (aka 'in_addr')}} 125 } 126 127 template<typename T> void h1(T (__stdcall M::* const )()) { } 128 129 void m1() { 130 h1<int>(&M::addP); 131 h1(&M::subtractP); 132 } 133 134 135 namespace signed_hex_i64 { 136 void f(long long); // expected-note {{candidate function}} 137 void f(int); // expected-note {{candidate function}} 138 void g() { 139 // This used to be controlled by -fms-extensions, but it is now under 140 // -fms-compatibility. 141 f(0xffffffffffffffffLL); // expected-error {{call to 'f' is ambiguous}} 142 f(0xffffffffffffffffi64); 143 } 144 } 145 146 // Enumeration types with a fixed underlying type. 147 const int seventeen = 17; 148 typedef int Int; 149 150 struct X0 { 151 enum E1 : Int { SomeOtherValue } field; 152 #if __cplusplus <= 199711L 153 // expected-warning@-2 {{enumeration types with a fixed underlying type are a C++11 extension}} 154 #endif 155 156 enum E1 : seventeen; 157 }; 158 159 #if __cplusplus <= 199711L 160 // expected-warning@+2 {{enumeration types with a fixed underlying type are a C++11 extension}} 161 #endif 162 enum : long long { 163 SomeValue = 0x100000000 164 }; 165 166 167 class AAA { 168 __declspec(dllimport) void f(void) { } 169 void f2(void); // expected-note{{previous declaration is here}} 170 }; 171 172 __declspec(dllimport) void AAA::f2(void) { // expected-error{{dllimport cannot be applied to non-inline function definition}} 173 // expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}} 174 175 } 176 177 178 179 template <class T> 180 class BB { 181 public: 182 void f(int g = 10 ); // expected-note {{previous definition is here}} 183 }; 184 185 template <class T> 186 void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}} 187 188 189 190 extern void static_func(); 191 void static_func(); // expected-note {{previous declaration is here}} 192 193 194 static void static_func() // expected-warning {{redeclaring non-static 'static_func' as static is a Microsoft extension}} 195 { 196 197 } 198 199 extern const int static_var; // expected-note {{previous declaration is here}} 200 static const int static_var = 3; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}} 201 202 void pointer_to_integral_type_conv(char* ptr) { 203 char ch = (char)ptr; 204 short sh = (short)ptr; 205 ch = (char)ptr; 206 sh = (short)ptr; 207 208 // These are valid C++. 209 bool b = (bool)ptr; 210 b = static_cast<bool>(ptr); 211 212 // This is bad. 213 b = reinterpret_cast<bool>(ptr); // expected-error {{cast from pointer to smaller type 'bool' loses information}} 214 } 215 216 struct PR11150 { 217 class X { 218 virtual void f() = 0; 219 }; 220 221 int array[__is_abstract(X)? 1 : -1]; 222 }; 223 224 void f() { int __except = 0; } 225 226 void ::f(); // expected-warning{{extra qualification on member 'f'}} 227 228 class C { 229 C::C(); // expected-warning{{extra qualification on member 'C'}} 230 }; 231 232 struct StructWithProperty { 233 __declspec(property(get=GetV)) int V1; 234 __declspec(property(put=SetV)) int V2; 235 __declspec(property(get=GetV, put=SetV_NotExist)) int V3; 236 __declspec(property(get=GetV_NotExist, put=SetV)) int V4; 237 __declspec(property(get=GetV, put=SetV)) int V5; 238 239 int GetV() { return 123; } 240 void SetV(int i) {} 241 }; 242 void TestProperty() { 243 StructWithProperty sp; 244 int i = sp.V2; // expected-error{{no getter defined for property 'V2'}} 245 sp.V1 = 12; // expected-error{{no setter defined for property 'V1'}} 246 int j = sp.V4; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}} 247 sp.V3 = 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}} 248 int k = sp.V5; 249 sp.V5 = k++; 250 } 251 252 /* 4 tests for PseudoObject, begin */ 253 struct SP1 254 { 255 bool operator()() { return true; } 256 }; 257 struct SP2 258 { 259 __declspec(property(get=GetV)) SP1 V; 260 SP1 GetV() { return SP1(); } 261 }; 262 void TestSP2() { 263 SP2 sp2; 264 bool b = sp2.V(); 265 } 266 267 struct SP3 { 268 template <class T> 269 void f(T t) {} 270 }; 271 template <class T> 272 struct SP4 273 { 274 __declspec(property(get=GetV)) int V; 275 int GetV() { return 123; } 276 void f() { SP3 s2; s2.f(V); } 277 }; 278 void TestSP4() { 279 SP4<int> s; 280 s.f(); 281 } 282 283 template <class T> 284 struct SP5 285 { 286 __declspec(property(get=GetV)) T V; 287 int GetV() { return 123; } 288 void f() { int *p = new int[V]; } 289 }; 290 291 template <class T> 292 struct SP6 293 { 294 public: 295 __declspec(property(get=GetV)) T V; 296 T GetV() { return 123; } 297 void f() { int t = V; } 298 }; 299 void TestSP6() { 300 SP6<int> c; 301 c.f(); 302 } 303 /* 4 tests for PseudoObject, end */ 304 305 // Property access: explicit, implicit, with Qualifier 306 struct SP7 { 307 __declspec(property(get=GetV, put=SetV)) int V; 308 int GetV() { return 123; } 309 void SetV(int v) {} 310 311 void ImplicitAccess() { int i = V; V = i; } 312 void ExplicitAccess() { int i = this->V; this->V = i; } 313 }; 314 struct SP8: public SP7 { 315 void AccessWithQualifier() { int i = SP7::V; SP7::V = i; } 316 }; 317 318 // Property usage 319 template <class T> 320 struct SP9 { 321 __declspec(property(get=GetV, put=SetV)) T V; 322 T GetV() { return 0; } 323 void SetV(T v) {} 324 bool f() { V = this->V; return V < this->V; } 325 void g() { V++; } 326 void h() { V*=2; } 327 }; 328 struct SP10 { 329 SP10(int v) {} 330 bool operator<(const SP10& v) { return true; } 331 SP10 operator*(int v) { return *this; } 332 SP10 operator+(int v) { return *this; } 333 SP10& operator=(const SP10& v) { return *this; } 334 }; 335 void TestSP9() { 336 SP9<int> c; 337 int i = c.V; // Decl initializer 338 i = c.V; // Binary op operand 339 c.SetV(c.V); // CallExpr arg 340 int *p = new int[c.V + 1]; // Array size 341 p[c.V] = 1; // Array index 342 343 c.V = 123; // Setter 344 345 c.V++; // Unary op operand 346 c.V *= 2; // Unary op operand 347 348 SP9<int*> c2; 349 c2.V[0] = 123; // Array 350 351 SP9<SP10> c3; 352 c3.f(); // Overloaded binary op operand 353 c3.g(); // Overloaded incdec op operand 354 c3.h(); // Overloaded unary op operand 355 } 356 357 union u { 358 int *i1; 359 int &i2; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}} 360 }; 361 362 // Property getter using reference. 363 struct SP11 { 364 __declspec(property(get=GetV)) int V; 365 int _v; 366 int& GetV() { return _v; } 367 void UseV(); 368 void TakePtr(int *) {} 369 void TakeRef(int &) {} 370 void TakeVal(int) {} 371 }; 372 373 void SP11::UseV() { 374 TakePtr(&V); 375 TakeRef(V); 376 TakeVal(V); 377 } 378 379 struct StructWithUnnamedMember { 380 __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}} 381 }; 382 383 struct MSPropertyClass { 384 int get() { return 42; } 385 int __declspec(property(get = get)) n; 386 }; 387 388 int *f(MSPropertyClass &x) { 389 return &x.n; // expected-error {{address of property expression requested}} 390 } 391 int MSPropertyClass::*g() { 392 return &MSPropertyClass::n; // expected-error {{address of property expression requested}} 393 } 394 395 namespace rdar14250378 { 396 class Bar {}; 397 398 namespace NyNamespace { 399 class Foo { 400 public: 401 Bar* EnsureBar(); 402 }; 403 404 class Baz : public Foo { 405 public: 406 friend class Bar; 407 }; 408 409 Bar* Foo::EnsureBar() { 410 return 0; 411 } 412 } 413 } 414 415 // expected-error@+1 {{'sealed' keyword not permitted with interface types}} 416 __interface InterfaceWithSealed sealed { 417 }; 418 419 struct SomeBase { 420 virtual void OverrideMe(); 421 422 // expected-note@+2 {{overridden virtual function is here}} 423 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} 424 virtual void SealedFunction() sealed; // expected-note {{overridden virtual function is here}} 425 }; 426 427 // expected-note@+2 {{'SealedType' declared here}} 428 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} 429 struct SealedType sealed : SomeBase { 430 // expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}} 431 // FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function. 432 virtual void SealedFunction(); // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}} 433 434 #if __cplusplus <= 199711L 435 // expected-warning@+2 {{'override' keyword is a C++11 extension}} 436 #endif 437 virtual void OverrideMe() override; 438 }; 439 440 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}} 441 struct InheritFromSealed : SealedType {}; 442 443 class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}} 444 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} 445 virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}} 446 }; 447 448 void AfterClassBody() { 449 // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}} 450 struct D {} __declspec(deprecated); 451 452 struct __declspec(align(4)) S {} __declspec(align(8)) s1; 453 S s2; 454 _Static_assert(__alignof(S) == 4, ""); 455 _Static_assert(__alignof(s1) == 8, ""); 456 _Static_assert(__alignof(s2) == 4, ""); 457 } 458 459 namespace PR24246 { 460 template <typename TX> struct A { 461 template <bool> struct largest_type_select; 462 template <> struct largest_type_select<false> { 463 blah x; // expected-error {{unknown type name 'blah'}} 464 }; 465 }; 466 } 467 468 class PR34109_class { 469 PR34109_class() {} 470 virtual ~PR34109_class() {} 471 }; 472 473 void operator delete(void *) throw(); 474 // expected-note@-1 {{previous declaration is here}} 475 __declspec(dllexport) void operator delete(void *) throw(); 476 // expected-error@-1 {{redeclaration of 'operator delete' cannot add 'dllexport' attribute}} 477 478 void PR34109(int* a) { 479 delete a; 480 } 481 482 namespace PR42089 { 483 struct S { 484 __attribute__((nothrow)) void Foo(); // expected-note {{previous declaration is here}} 485 __attribute__((nothrow)) void Bar(); 486 }; 487 void S::Foo(){} // expected-warning {{is missing exception specification}} 488 __attribute__((nothrow)) void S::Bar(){} 489 } 490 491 #elif TEST2 492 493 // Check that __unaligned is not recognized if MS extensions are not enabled 494 typedef char __unaligned *aligned_type; // expected-error {{expected ';' after top level declarator}} 495 496 #elif TEST3 497 498 namespace PR32750 { 499 template<typename T> struct A {}; 500 template<typename T> struct B : A<A<T>> { A<T>::C::D d; }; // expected-error {{missing 'typename' prior to dependent type name 'A<T>::C::D'}} 501 } 502 503 #else 504 505 #error Unknown test mode 506 507 #endif 508 509