MicrosoftExtensions.cpp revision a8ef3ac9fa7637fad33d52614794b92e2261d65b
1// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexceptions -fcxx-exceptions 2 3 4// ::type_info is predeclared with forward class declartion 5void f(const type_info &a); 6 7 8// Microsoft doesn't validate exception specification. 9void foo(); // expected-note {{previous declaration}} 10void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}} 11 12void r6() throw(...); // expected-note {{previous declaration}} 13void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}} 14 15struct Base { 16 virtual void f2(); 17 virtual void f3() throw(...); 18}; 19 20struct Derived : Base { 21 virtual void f2() throw(...); 22 virtual void f3(); 23}; 24 25 26// MSVC allows type definition in anonymous union and struct 27struct A 28{ 29 union 30 { 31 int a; 32 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 33 { 34 int c; 35 } d; 36 37 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 38 { 39 int e; 40 int ee; 41 } f; 42 43 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 44 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}} 45 }; 46 47 struct 48 { 49 int a2; 50 51 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 52 { 53 int c2; 54 } d2; 55 56 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 57 { 58 int e2; 59 int ee2; 60 } f2; 61 62 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 63 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}} 64 }; 65}; 66 67// __stdcall handling 68struct M { 69 int __stdcall addP(); 70 float __stdcall subtractP(); 71}; 72 73template<typename T> void h1(T (__stdcall M::* const )()) { } 74 75void m1() { 76 h1<int>(&M::addP); 77 h1(&M::subtractP); 78} 79 80//MSVC allows forward enum declaration 81enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}} 82ENUM *var = 0; 83ENUM var2 = (ENUM)3; 84enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}} 85 86 87enum ENUM2 { 88 ENUM2_a = (enum ENUM2) 4, 89 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}} 90 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}} 91}; 92 93 94void f(long long); 95void f(int); 96 97int main() 98{ 99 // This is an ambiguous call in standard C++. 100 // This calls f(long long) in Microsoft mode because LL is always signed. 101 f(0xffffffffffffffffLL); 102 f(0xffffffffffffffffi64); 103} 104 105// Enumeration types with a fixed underlying type. 106const int seventeen = 17; 107typedef int Int; 108 109struct X0 { 110 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} 111 enum E1 : seventeen; 112}; 113 114enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}} 115 SomeValue = 0x100000000 116}; 117 118 119class AAA { 120__declspec(dllimport) void f(void) { } 121void f2(void); 122}; 123 124__declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}} 125 126} 127 128 129 130template <class T> 131class BB { 132public: 133 void f(int g = 10 ); // expected-note {{previous definition is here}} 134}; 135 136template <class T> 137void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}} 138 139 140namespace MissingTypename { 141 142template<class T> class A { 143public: 144 typedef int TYPE; 145}; 146 147template<class T> class B { 148public: 149 typedef int TYPE; 150}; 151 152 153template<class T, class U> 154class C : private A<T>, public B<U> { 155public: 156 typedef A<T> Base1; 157 typedef B<U> Base2; 158 typedef A<U> Base3; 159 160 A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}} 161 Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}} 162 163 B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}} 164 Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}} 165 166 A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}} 167 Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}} 168 }; 169 170} 171 172 173 174 175extern void static_func(); 176void static_func(); // expected-note {{previous declaration is here}} 177 178 179static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}} 180{ 181 182} 183 184long function_prototype(int a); 185long (*function_ptr)(int a); 186 187void function_to_voidptr_conv() { 188 void *a1 = function_prototype; 189 void *a2 = &function_prototype; 190 void *a1 = function_ptr; 191 void *a2 = &function_ptr; 192} 193