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
8 // Microsoft doesn't validate exception specification.
9 namespace microsoft_exception_spec {
11 void foo(); // expected-note {{previous declaration}}
12 void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
14 void r6() throw(...); // expected-note {{previous declaration}}
15 void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
19 virtual void f3() throw(...);
22 struct Derived : Base {
23 virtual void f2() throw(...);
29 #if __cplusplus <= 199711L
30 // expected-note@-2 {{overridden virtual function is here}}
36 #if __cplusplus <= 199711L
37 // expected-warning@-2 {{exception specification of overriding function is more lax than base version}}
43 // MSVC allows type definition in anonymous union and struct
49 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
54 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
60 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
61 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
68 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
73 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
79 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
80 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
87 float __stdcall subtractP();
90 // __unaligned handling
91 typedef char __unaligned *aligned_type;
92 typedef struct UnalignedTag { int f; } __unaligned *aligned_type2;
93 typedef char __unaligned aligned_type3;
95 struct aligned_type4 {
99 __unaligned int aligned_type4::*p1_aligned_type4 = &aligned_type4::i;
100 int aligned_type4::* __unaligned p2_aligned_type4 = &aligned_type4::i;
101 __unaligned int aligned_type4::* __unaligned p3_aligned_type4 = &aligned_type4::i;
102 void (aligned_type4::*__unaligned p4_aligned_type4)();
104 // Check that __unaligned qualifier can be used for overloading
105 void foo_unaligned(int *arg) {}
106 void foo_unaligned(__unaligned int *arg) {}
107 void foo_unaligned(int arg) {} // expected-note {{previous definition is here}}
108 void foo_unaligned(__unaligned int arg) {} // expected-error {{redefinition of 'foo_unaligned'}}
109 class A_unaligned {};
110 class B_unaligned : public A_unaligned {};
111 int foo_unaligned(__unaligned A_unaligned *arg) { return 0; }
112 void *foo_unaligned(B_unaligned *arg) { return 0; }
114 void test_unaligned() {
118 __unaligned int *p2 = 0;
121 __unaligned B_unaligned *p3 = 0;
122 int p4 = foo_unaligned(p3);
124 B_unaligned *p5 = p3; // expected-error {{cannot initialize a variable of type 'B_unaligned *' with an lvalue of type '__unaligned B_unaligned *'}}
126 __unaligned B_unaligned *p6 = p3;
128 p1_aligned_type4 = p2_aligned_type4;
129 p2_aligned_type4 = p1_aligned_type4; // expected-error {{assigning to 'int aligned_type4::*' from incompatible type '__unaligned int aligned_type4::*'}}
130 p3_aligned_type4 = p1_aligned_type4;
132 __unaligned int a[10];
133 int *b = a; // expected-error {{cannot initialize a variable of type 'int *' with an lvalue of type '__unaligned int [10]'}}
137 // We should accept assignment of an __unaligned pointer to a non-__unaligned
139 typedef struct _ITEMIDLIST { int i; } ITEMIDLIST;
140 typedef ITEMIDLIST __unaligned *LPITEMIDLIST;
141 extern "C" __declspec(dllimport) void __stdcall CoTaskMemFree(void* pv);
142 __inline void FreeIDListArray(LPITEMIDLIST *ppidls) {
143 CoTaskMemFree(*ppidls);
144 __unaligned int *x = 0;
149 // We should accept type conversion of __unaligned to non-__unaligned references
150 typedef struct in_addr {
152 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 *}}
153 in_addr(in_addr *a) {} // expected-note {{candidate constructor not viable: 1st argument ('__unaligned IN_ADDR *' (aka '__unaligned in_addr *')) would lose __unaligned qualifier}}
156 void f(IN_ADDR __unaligned *a) {
157 IN_ADDR local_addr = *a;
158 IN_ADDR local_addr2 = a; // expected-error {{no viable conversion from '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to 'IN_ADDR' (aka 'in_addr')}}
161 template<typename T> void h1(T (__stdcall M::* const )()) { }
169 namespace signed_hex_i64 {
170 void f(long long); // expected-note {{candidate function}}
171 void f(int); // expected-note {{candidate function}}
173 // This used to be controlled by -fms-extensions, but it is now under
174 // -fms-compatibility.
175 f(0xffffffffffffffffLL); // expected-error {{call to 'f' is ambiguous}}
176 f(0xffffffffffffffffi64);
180 // Enumeration types with a fixed underlying type.
181 const int seventeen = 17;
185 enum E1 : Int { SomeOtherValue } field;
186 #if __cplusplus <= 199711L
187 // expected-warning@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
193 #if __cplusplus <= 199711L
194 // expected-warning@+2 {{enumeration types with a fixed underlying type are a C++11 extension}}
197 SomeValue = 0x100000000
202 __declspec(dllimport) void f(void) { }
203 void f2(void); // expected-note{{previous declaration is here}}
206 __declspec(dllimport) void AAA::f2(void) { // expected-error{{dllimport cannot be applied to non-inline function definition}}
207 // expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}}
216 void f(int g = 10 ); // expected-note {{previous definition is here}}
220 void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
224 extern void static_func();
225 void static_func(); // expected-note {{previous declaration is here}}
228 static void static_func() // expected-warning {{redeclaring non-static 'static_func' as static is a Microsoft extension}}
233 extern const int static_var; // expected-note {{previous declaration is here}}
234 static const int static_var = 3; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}}
236 void pointer_to_integral_type_conv(char* ptr) {
238 short sh = (short)ptr;
242 // These are valid C++.
244 b = static_cast<bool>(ptr);
247 b = reinterpret_cast<bool>(ptr); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
252 virtual void f() = 0;
255 int array[__is_abstract(X)? 1 : -1];
258 void f() { int __except = 0; }
260 void ::f(); // expected-warning{{extra qualification on member 'f'}}
263 C::C(); // expected-warning{{extra qualification on member 'C'}}
266 struct StructWithProperty {
267 __declspec(property(get=GetV)) int V1;
268 __declspec(property(put=SetV)) int V2;
269 __declspec(property(get=GetV, put=SetV_NotExist)) int V3;
270 __declspec(property(get=GetV_NotExist, put=SetV)) int V4;
271 __declspec(property(get=GetV, put=SetV)) int V5;
273 int GetV() { return 123; }
276 void TestProperty() {
277 StructWithProperty sp;
278 int i = sp.V2; // expected-error{{no getter defined for property 'V2'}}
279 sp.V1 = 12; // expected-error{{no setter defined for property 'V1'}}
280 int j = sp.V4; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}}
281 sp.V3 = 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}}
286 /* 4 tests for PseudoObject, begin */
289 bool operator()() { return true; }
293 __declspec(property(get=GetV)) SP1 V;
294 SP1 GetV() { return SP1(); }
308 __declspec(property(get=GetV)) int V;
309 int GetV() { return 123; }
310 void f() { SP3 s2; s2.f(V); }
320 __declspec(property(get=GetV)) T V;
321 int GetV() { return 123; }
322 void f() { int *p = new int[V]; }
329 __declspec(property(get=GetV)) T V;
330 T GetV() { return 123; }
331 void f() { int t = V; }
337 /* 4 tests for PseudoObject, end */
339 // Property access: explicit, implicit, with Qualifier
341 __declspec(property(get=GetV, put=SetV)) int V;
342 int GetV() { return 123; }
345 void ImplicitAccess() { int i = V; V = i; }
346 void ExplicitAccess() { int i = this->V; this->V = i; }
348 struct SP8: public SP7 {
349 void AccessWithQualifier() { int i = SP7::V; SP7::V = i; }
355 __declspec(property(get=GetV, put=SetV)) T V;
356 T GetV() { return 0; }
358 bool f() { V = this->V; return V < this->V; }
364 bool operator<(const SP10& v) { return true; }
365 SP10 operator*(int v) { return *this; }
366 SP10 operator+(int v) { return *this; }
367 SP10& operator=(const SP10& v) { return *this; }
371 int i = c.V; // Decl initializer
372 i = c.V; // Binary op operand
373 c.SetV(c.V); // CallExpr arg
374 int *p = new int[c.V + 1]; // Array size
375 p[c.V] = 1; // Array index
379 c.V++; // Unary op operand
380 c.V *= 2; // Unary op operand
383 c2.V[0] = 123; // Array
386 c3.f(); // Overloaded binary op operand
387 c3.g(); // Overloaded incdec op operand
388 c3.h(); // Overloaded unary op operand
393 int &i2; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
396 // Property getter using reference.
398 __declspec(property(get=GetV)) int V;
400 int& GetV() { return _v; }
402 void TakePtr(int *) {}
403 void TakeRef(int &) {}
413 struct StructWithUnnamedMember {
414 __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}}
417 struct MSPropertyClass {
418 int get() { return 42; }
419 int __declspec(property(get = get)) n;
422 int *f(MSPropertyClass &x) {
423 return &x.n; // expected-error {{address of property expression requested}}
425 int MSPropertyClass::*g() {
426 return &MSPropertyClass::n; // expected-error {{address of property expression requested}}
429 namespace rdar14250378 {
432 namespace NyNamespace {
438 class Baz : public Foo {
443 Bar* Foo::EnsureBar() {
449 // expected-error@+1 {{'sealed' keyword not permitted with interface types}}
450 __interface InterfaceWithSealed sealed {
454 virtual void OverrideMe();
456 // expected-note@+2 {{overridden virtual function is here}}
457 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
458 virtual void SealedFunction() sealed; // expected-note {{overridden virtual function is here}}
461 // expected-note@+2 {{'SealedType' declared here}}
462 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
463 struct SealedType sealed : SomeBase {
464 // expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}}
465 // FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function.
466 virtual void SealedFunction(); // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}}
468 #if __cplusplus <= 199711L
469 // expected-warning@+2 {{'override' keyword is a C++11 extension}}
471 virtual void OverrideMe() override;
474 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
475 struct InheritFromSealed : SealedType {};
477 void AfterClassBody() {
478 // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
479 struct D {} __declspec(deprecated);
481 struct __declspec(align(4)) S {} __declspec(align(8)) s1;
483 _Static_assert(__alignof(S) == 4, "");
484 _Static_assert(__alignof(s1) == 8, "");
485 _Static_assert(__alignof(s2) == 4, "");
489 template <typename TX> struct A {
490 template <bool> struct largest_type_select;
491 // expected-warning@+1 {{explicit specialization of 'largest_type_select' within class scope is a Microsoft extension}}
492 template <> struct largest_type_select<false> {
493 blah x; // expected-error {{unknown type name 'blah'}}
500 int fn() throw(); // expected-note {{previous declaration is here}}
503 int S::fn() { return 0; } // expected-warning {{is missing exception specification}}
508 // Check that __unaligned is not recognized if MS extensions are not enabled
509 typedef char __unaligned *aligned_type; // expected-error {{expected ';' after top level declarator}}
513 #error Unknown test mode