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 // Microsoft doesn't validate exception specification. 5 namespace microsoft_exception_spec { 6 7 void foo(); // expected-note {{previous declaration}} 8 void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}} 9 10 void r6() throw(...); // expected-note {{previous declaration}} 11 void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}} 12 13 struct Base { 14 virtual void f2(); 15 virtual void f3() throw(...); 16 }; 17 18 struct Derived : Base { 19 virtual void f2() throw(...); 20 virtual void f3(); 21 }; 22 23 class A { 24 virtual ~A() throw(); // expected-note {{overridden virtual function is here}} 25 }; 26 27 class B : public A { 28 virtual ~B(); // expected-warning {{exception specification of overriding function is more lax than base version}} 29 }; 30 31 } 32 33 // MSVC allows type definition in anonymous union and struct 34 struct A 35 { 36 union 37 { 38 int a; 39 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 40 { 41 int c; 42 } d; 43 44 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 45 { 46 int e; 47 int ee; 48 } f; 49 50 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 51 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 52 }; 53 54 struct 55 { 56 int a2; 57 58 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 59 { 60 int c2; 61 } d2; 62 63 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 64 { 65 int e2; 66 int ee2; 67 } f2; 68 69 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 70 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 71 }; 72 }; 73 74 // __stdcall handling 75 struct M { 76 int __stdcall addP(); 77 float __stdcall subtractP(); 78 }; 79 80 // __unaligned handling 81 typedef char __unaligned *aligned_type; 82 83 84 template<typename T> void h1(T (__stdcall M::* const )()) { } 85 86 void m1() { 87 h1<int>(&M::addP); 88 h1(&M::subtractP); 89 } 90 91 92 93 94 95 void f(long long); 96 void f(int); 97 98 int main() 99 { 100 // This is an ambiguous call in standard C++. 101 // This calls f(long long) in Microsoft mode because LL is always signed. 102 f(0xffffffffffffffffLL); 103 f(0xffffffffffffffffi64); 104 } 105 106 // Enumeration types with a fixed underlying type. 107 const int seventeen = 17; 108 typedef int Int; 109 110 struct X0 { 111 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}} 112 enum E1 : seventeen; 113 }; 114 115 enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}} 116 SomeValue = 0x100000000 117 }; 118 119 120 class AAA { 121 __declspec(dllimport) void f(void) { } 122 void f2(void); 123 }; 124 125 __declspec(dllimport) void AAA::f2(void) { // expected-error {{'dllimport' attribute can be applied only to symbol}} 126 127 } 128 129 130 131 template <class T> 132 class BB { 133 public: 134 void f(int g = 10 ); // expected-note {{previous definition is here}} 135 }; 136 137 template <class T> 138 void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}} 139 140 141 142 extern void static_func(); 143 void static_func(); // expected-note {{previous declaration is here}} 144 145 146 static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}} 147 { 148 149 } 150 151 long function_prototype(int a); 152 long (*function_ptr)(int a); 153 154 void function_to_voidptr_conv() { 155 void *a1 = function_prototype; 156 void *a2 = &function_prototype; 157 void *a3 = function_ptr; 158 } 159 160 161 void pointer_to_integral_type_conv(char* ptr) { 162 char ch = (char)ptr; 163 short sh = (short)ptr; 164 ch = (char)ptr; 165 sh = (short)ptr; 166 167 // These are valid C++. 168 bool b = (bool)ptr; 169 b = static_cast<bool>(ptr); 170 171 // This is bad. 172 b = reinterpret_cast<bool>(ptr); // expected-error {{cast from pointer to smaller type 'bool' loses information}} 173 } 174 175 namespace friend_as_a_forward_decl { 176 177 class A { 178 class Nested { 179 friend class B; 180 B* b; 181 }; 182 B* b; 183 }; 184 B* global_b; 185 186 187 void f() 188 { 189 class Local { 190 friend class Z; 191 Z* b; 192 }; 193 Z* b; 194 } 195 196 } 197 198 struct PR11150 { 199 class X { 200 virtual void f() = 0; 201 }; 202 203 int array[__is_abstract(X)? 1 : -1]; 204 }; 205 206 void f() { int __except = 0; } 207 208 void ::f(); // expected-warning{{extra qualification on member 'f'}} 209 210 class C { 211 C::C(); // expected-warning{{extra qualification on member 'C'}} 212 }; 213 214 struct StructWithProperty { 215 __declspec(property(get=GetV)) int V1; 216 __declspec(property(put=SetV)) int V2; 217 __declspec(property(get=GetV, put=SetV_NotExist)) int V3; 218 __declspec(property(get=GetV_NotExist, put=SetV)) int V4; 219 __declspec(property(get=GetV, put=SetV)) int V5; 220 221 int GetV() { return 123; } 222 void SetV(int i) {} 223 }; 224 void TestProperty() { 225 StructWithProperty sp; 226 int i = sp.V2; // expected-error{{no getter defined for property 'V2'}} 227 sp.V1 = 12; // expected-error{{no setter defined for property 'V1'}} 228 int j = sp.V4; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}} 229 sp.V3 = 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}} 230 int k = sp.V5; 231 sp.V5 = k++; 232 } 233 234 /* 4 tests for PseudoObject, begin */ 235 struct SP1 236 { 237 bool operator()() { return true; } 238 }; 239 struct SP2 240 { 241 __declspec(property(get=GetV)) SP1 V; 242 SP1 GetV() { return SP1(); } 243 }; 244 void TestSP2() { 245 SP2 sp2; 246 bool b = sp2.V(); 247 } 248 249 struct SP3 { 250 template <class T> 251 void f(T t) {} 252 }; 253 template <class T> 254 struct SP4 255 { 256 __declspec(property(get=GetV)) int V; 257 int GetV() { return 123; } 258 void f() { SP3 s2; s2.f(V); } 259 }; 260 void TestSP4() { 261 SP4<int> s; 262 s.f(); 263 } 264 265 template <class T> 266 struct SP5 267 { 268 __declspec(property(get=GetV)) T V; 269 int GetV() { return 123; } 270 void f() { int *p = new int[V]; } 271 }; 272 273 template <class T> 274 struct SP6 275 { 276 public: 277 __declspec(property(get=GetV)) T V; 278 T GetV() { return 123; } 279 void f() { int t = V; } 280 }; 281 void TestSP6() { 282 SP6<int> c; 283 c.f(); 284 } 285 /* 4 tests for PseudoObject, end */ 286 287 // Property access: explicit, implicit, with Qualifier 288 struct SP7 { 289 __declspec(property(get=GetV, put=SetV)) int V; 290 int GetV() { return 123; } 291 void SetV(int v) {} 292 293 void ImplicitAccess() { int i = V; V = i; } 294 void ExplicitAccess() { int i = this->V; this->V = i; } 295 }; 296 struct SP8: public SP7 { 297 void AccessWithQualifier() { int i = SP7::V; SP7::V = i; } 298 }; 299 300 // Property usage 301 template <class T> 302 struct SP9 { 303 __declspec(property(get=GetV, put=SetV)) T V; 304 T GetV() { return 0; } 305 void SetV(T v) {} 306 void f() { V = this->V; V < this->V; } 307 void g() { V++; } 308 void h() { V*=2; } 309 }; 310 struct SP10 { 311 SP10(int v) {} 312 bool operator<(const SP10& v) { return true; } 313 SP10 operator*(int v) { return *this; } 314 SP10 operator+(int v) { return *this; } 315 SP10& operator=(const SP10& v) { return *this; } 316 }; 317 void TestSP9() { 318 SP9<int> c; 319 int i = c.V; // Decl initializer 320 i = c.V; // Binary op operand 321 c.SetV(c.V); // CallExpr arg 322 int *p = new int[c.V + 1]; // Array size 323 p[c.V] = 1; // Array index 324 325 c.V = 123; // Setter 326 327 c.V++; // Unary op operand 328 c.V *= 2; // Unary op operand 329 330 SP9<int*> c2; 331 c2.V[0] = 123; // Array 332 333 SP9<SP10> c3; 334 c3.f(); // Overloaded binary op operand 335 c3.g(); // Overloaded incdec op operand 336 c3.h(); // Overloaded unary op operand 337 } 338 339 union u { 340 int *i1; 341 int &i2; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}} 342 }; 343 344 // Property getter using reference. 345 struct SP11 { 346 __declspec(property(get=GetV)) int V; 347 int _v; 348 int& GetV() { return _v; } 349 void UseV(); 350 void TakePtr(int *) {} 351 void TakeRef(int &) {} 352 void TakeVal(int) {} 353 }; 354 355 void SP11::UseV() { 356 TakePtr(&V); 357 TakeRef(V); 358 TakeVal(V); 359 } 360 361 struct StructWithUnnamedMember { 362 __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}} 363 }; 364 365 namespace rdar14250378 { 366 class Bar {}; 367 368 namespace NyNamespace { 369 class Foo { 370 public: 371 Bar* EnsureBar(); 372 }; 373 374 class Baz : public Foo { 375 public: 376 friend class Bar; 377 }; 378 379 Bar* Foo::EnsureBar() { 380 return 0; 381 } 382 } 383 } 384 385 // expected-error@+1 {{'sealed' keyword not permitted with interface types}} 386 __interface InterfaceWithSealed sealed { 387 }; 388 389 struct SomeBase { 390 virtual void OverrideMe(); 391 392 // expected-note@+2 {{overridden virtual function is here}} 393 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} 394 virtual void SealedFunction() sealed; 395 }; 396 397 // expected-note@+2 {{'SealedType' declared here}} 398 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}} 399 struct SealedType sealed : SomeBase { 400 // expected-error@+1 {{declaration of 'SealedFunction' overrides a 'sealed' function}} 401 virtual void SealedFunction(); 402 403 // expected-warning@+1 {{'override' keyword is a C++11 extension}} 404 virtual void OverrideMe() override; 405 }; 406 407 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}} 408 struct InheritFromSealed : SealedType {}; 409 410 void AfterClassBody() { 411 // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}} 412 struct D {} __declspec(deprecated); 413 414 struct __declspec(align(4)) S {} __declspec(align(8)) s1; 415 S s2; 416 _Static_assert(__alignof(S) == 4, ""); 417 _Static_assert(__alignof(s1) == 8, ""); 418 _Static_assert(__alignof(s2) == 4, ""); 419 } 420