MicrosoftExtensions.cpp revision b4746036322385bf27d33ec1fc3c82a8bb3d1e58
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.
9namespace microsoft_exception_spec {
10
11void foo(); // expected-note {{previous declaration}}
12void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
13
14void r6() throw(...); // expected-note {{previous declaration}}
15void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
16
17struct Base {
18  virtual void f2();
19  virtual void f3() throw(...);
20};
21
22struct Derived : Base {
23  virtual void f2() throw(...);
24  virtual void f3();
25};
26
27class A {
28  virtual ~A() throw();  // expected-note {{overridden virtual function is here}}
29};
30
31class 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
38struct 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
79struct M {
80    int __stdcall addP();
81    float __stdcall subtractP();
82};
83
84template<typename T> void h1(T (__stdcall M::* const )()) { }
85
86void m1() {
87  h1<int>(&M::addP);
88  h1(&M::subtractP);
89}
90
91//MSVC allows forward enum declaration
92enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
93ENUM *var = 0;
94ENUM var2 = (ENUM)3;
95enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
96
97
98enum ENUM2 {
99	ENUM2_a = (enum ENUM2) 4,
100	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
101	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
102};
103
104
105void f(long long);
106void f(int);
107
108int main()
109{
110  // This is an ambiguous call in standard C++.
111  // This calls f(long long) in Microsoft mode because LL is always signed.
112  f(0xffffffffffffffffLL);
113  f(0xffffffffffffffffi64);
114}
115
116// Enumeration types with a fixed underlying type.
117const int seventeen = 17;
118typedef int Int;
119
120struct X0 {
121  enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
122  enum E1 : seventeen;
123};
124
125enum : long long {  // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
126  SomeValue = 0x100000000
127};
128
129
130class AAA {
131__declspec(dllimport) void f(void) { }
132void f2(void);
133};
134
135__declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}}
136
137}
138
139
140
141template <class T>
142class BB {
143public:
144   void f(int g = 10 ); // expected-note {{previous definition is here}}
145};
146
147template <class T>
148void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
149
150
151namespace MissingTypename {
152
153template<class T> class A {
154public:
155	 typedef int TYPE;
156};
157
158template<class T> class B {
159public:
160	 typedef int TYPE;
161};
162
163
164template<class T, class U>
165class C : private A<T>, public B<U> {
166public:
167   typedef A<T> Base1;
168   typedef B<U> Base2;
169   typedef A<U> Base3;
170
171   A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
172   Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
173
174   B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
175   Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
176
177   A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
178   Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
179 };
180
181}
182
183
184
185
186extern void static_func();
187void static_func(); // expected-note {{previous declaration is here}}
188
189
190static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}}
191{
192
193}
194
195long function_prototype(int a);
196long (*function_ptr)(int a);
197
198void function_to_voidptr_conv() {
199   void *a1 = function_prototype;
200   void *a2 = &function_prototype;
201   void *a3 = function_ptr;
202}
203
204
205void pointer_to_integral_type_conv(char* ptr) {
206   char ch = (char)ptr;
207   short sh = (short)ptr;
208   ch = (char)ptr;
209   sh = (short)ptr;
210}
211
212namespace ms_using_declaration_bug {
213
214class A {
215public:
216  int f();
217};
218
219class B : public A {
220private:
221  using A::f;
222};
223
224class C : public B {
225private:
226  using B::f; // expected-warning {{using declaration refers to inaccessible member 'ms_using_declaration_bug::B::f', which refers to accessible member 'ms_using_declaration_bug::A::f', accepted for Microsoft compatibility}}
227};
228
229}
230
231
232
233namespace friend_as_a_forward_decl {
234
235class A {
236  class Nested {
237    friend class B;
238    B* b;
239  };
240  B* b;
241};
242B* global_b;
243
244
245void f()
246{
247  class Local {
248    friend class Z;
249    Z* b;
250  };
251  Z* b;
252}
253
254 }