1 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.28
2 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.27
3 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=19.00
4 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions -fms-compatibility-version=18.00
5 
6 #if defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT
7 char16_t x;
8 char32_t y;
9 #else
10 typedef unsigned short char16_t;
11 typedef unsigned int char32_t;
12 #endif
13 
14 _Atomic(int) z;
15 template <typename T>
16 struct _Atomic {
_Atomic_Atomic17   _Atomic() {}
~_Atomic_Atomic18   ~_Atomic() {}
19 };
20 template <typename T>
21 struct atomic : _Atomic<T> {
22   typedef _Atomic<T> TheBase;
23   TheBase field;
24 };
25 _Atomic(int) alpha;
26 
27 typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
28 
29 namespace ms_conversion_rules {
30 
31 void f(float a);
32 void f(int a);
33 #if _MSC_VER >= 1928
34 // expected-note@-3 2 {{candidate function}}
35 // expected-note@-3 2 {{candidate function}}
36 #endif
37 
test()38 void test()
39 {
40     long a = 0;
41     f((long)0);
42     f(a);
43 #if _MSC_VER >= 1928
44 // expected-error@-3 {{call to 'f' is ambiguous}}
45 // expected-error@-3 {{call to 'f' is ambiguous}}
46 #endif
47 }
48 
49 }
50 
51 
52 namespace ms_predefined_types {
53   // ::type_info is a built-in forward class declaration.
54   void f(const type_info &a);
55   void f(size_t);
56 }
57 
58 
59 namespace ms_protected_scope {
60   struct C { C(); };
61 
jump_over_variable_init(bool b)62   int jump_over_variable_init(bool b) {
63     if (b)
64       goto foo; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
65     C c; // expected-note {{jump bypasses variable initialization}}
66   foo:
67     return 1;
68   }
69 
70 struct Y {
71   ~Y();
72 };
73 
jump_over_var_with_dtor()74 void jump_over_var_with_dtor() {
75   goto end; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}}
76   Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
77  end:
78     ;
79 }
80 
jump_over_variable_case(int c)81   void jump_over_variable_case(int c) {
82     switch (c) {
83     case 0:
84       int x = 56; // expected-note {{jump bypasses variable initialization}}
85     case 1:       // expected-error {{cannot jump}}
86       x = 10;
87     }
88   }
89 
90 
exception_jump()91 void exception_jump() {
92   goto l2; // expected-error {{cannot jump}}
93   try { // expected-note {{jump bypasses initialization of try block}}
94      l2: ;
95   } catch(int) {
96   }
97 }
98 
jump_over_indirect_goto()99 int jump_over_indirect_goto() {
100   static void *ps[] = { &&a0 };
101   goto *&&a0; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
102   int a = 3; // expected-note {{jump bypasses variable initialization}}
103  a0:
104   return 0;
105 }
106 
107 }
108 
109 namespace PR11826 {
110   struct pair {
pairPR11826::pair111     pair(int v) { }
112 #if _MSC_VER >= 1900
operator =PR11826::pair113     void operator=(pair&& rhs) { } // expected-note {{copy constructor is implicitly deleted because 'pair' has a user-declared move assignment operator}}
114 #else
operator =PR11826::pair115     void operator=(pair&& rhs) { }
116 #endif
117   };
f()118   void f() {
119     pair p0(3);
120 #if _MSC_VER >= 1900
121     pair p = p0; // expected-error {{call to implicitly-deleted copy constructor of 'PR11826::pair'}}
122 #else
123     pair p = p0;
124 #endif
125   }
126 }
127 
128 namespace PR11826_for_symmetry {
129   struct pair {
pairPR11826_for_symmetry::pair130     pair(int v) { }
131 #if _MSC_VER >= 1900
pairPR11826_for_symmetry::pair132     pair(pair&& rhs) { } // expected-note {{copy assignment operator is implicitly deleted because 'pair' has a user-declared move constructor}}
133 #else
pairPR11826_for_symmetry::pair134     pair(pair&& rhs) { }
135 #endif
136   };
f()137   void f() {
138     pair p0(3);
139     pair p(4);
140 #if _MSC_VER >= 1900
141     p = p0; // expected-error {{object of type 'PR11826_for_symmetry::pair' cannot be assigned because its copy assignment operator is implicitly deleted}}
142 #else
143     p = p0;
144 #endif
145   }
146 }
147 
148 namespace ms_using_declaration_bug {
149 
150 class A {
151 public:
152   int f();
153 };
154 
155 class B : public A {
156 private:
157   using A::f;
g()158   void g() {
159     f(); // no diagnostic
160   }
161 };
162 
163 class C : public B {
164 private:
165   using B::f; // expected-warning {{using declaration referring to inaccessible member 'ms_using_declaration_bug::B::f' (which refers to accessible member 'ms_using_declaration_bug::A::f') is a Microsoft compatibility extension}}
166 };
167 
168 }
169 
170 namespace using_tag_redeclaration
171 {
172   struct S;
173   namespace N {
174     using ::using_tag_redeclaration::S;
175     struct S {}; // expected-note {{previous definition is here}}
176   }
f()177   void f() {
178     N::S s1;
179     S s2;
180   }
g()181   void g() {
182     struct S; // expected-note {{forward declaration of 'S'}}
183     S s3; // expected-error {{variable has incomplete type 'S'}}
184   }
h()185   void h() {
186     using ::using_tag_redeclaration::S;
187     struct S {}; // expected-error {{redefinition of 'S'}}
188   }
189 }
190 
191 
192 namespace MissingTypename {
193 
194 template<class T> class A {
195 public:
196 	 typedef int TYPE;
197 };
198 
199 template<class T> class B {
200 public:
201 	 typedef int TYPE;
202 };
203 
204 
205 template<class T, class U>
206 class C : private A<T>, public B<U> {
207 public:
208    typedef A<T> Base1;
209    typedef B<U> Base2;
210    typedef A<U> Base3;
211 
212    A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
213    Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
214 
215    B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
216    Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
217 
218    A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
219    Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
220  };
221 
222 class D {
223 public:
224     typedef int Type;
225 };
226 
227 template <class T>
function_missing_typename(const T::Type param)228 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
229 {
230     const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
231 }
232 
233 template void function_missing_typename<D>(const D::Type param);
234 
235 }
236 
237 //MSVC allows forward enum declaration
238 enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
239 ENUM *var = 0;
240 ENUM var2 = (ENUM)3;
241 enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
242 
243 enum ENUM1 { kA };
244 enum ENUM1;  // This way round is fine.
245 
246 enum ENUM2 {
247 	ENUM2_a = (enum ENUM2) 4,
248 	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
249 	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
250 };
251 
252 namespace NsEnumForwardDecl {
253   enum E *p; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
254   extern E e;
255 }
256 // Clang used to complain that NsEnumForwardDecl::E was undeclared below.
257 NsEnumForwardDecl::E NsEnumForwardDecl_e;
258 namespace NsEnumForwardDecl {
259   extern E e;
260 }
261 
262 namespace PR11791 {
263   template<class _Ty>
del(_Ty * _Ptr)264   void del(_Ty *_Ptr) {
265     _Ptr->~_Ty();  // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
266   }
267 
f()268   void f() {
269     int* a = 0;
270     del((void*)a);  // expected-note {{in instantiation of function template specialization}}
271   }
272 }
273 
274 namespace IntToNullPtrConv {
275   struct Foo {
276     static const int ZERO = 0;
277     typedef void (Foo::*MemberFcnPtr)();
278   };
279 
280   struct Bar {
281     const Foo::MemberFcnPtr pB;
282   };
283 
284   Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
285 
get_n()286   template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
287   int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
288 
289   // FIXME: MSVC accepts this.
290   constexpr float k = 0;
291   int *p1 = (int)k; // expected-error {{cannot initialize}}
292 
293   constexpr int n = 0;
294   const int &r = n;
295   int *p2 = (int)r; // expected-error {{cannot initialize}}
296 
f()297   constexpr int f() { return 0; }
298   int *p = f(); // expected-error {{cannot initialize}}
299 }
300 
301 namespace signed_hex_i64 {
302 void f(long long);
303 void f(int);
g()304 void g() {
305   // This is an ambiguous call in standard C++.
306   // This calls f(long long) in Microsoft mode because LL is always signed.
307   f(0xffffffffffffffffLL);
308   f(0xffffffffffffffffi64);
309 }
310 }
311 
312 typedef void (*FnPtrTy)();
313 void (*PR23733_1)() = static_cast<FnPtrTy>((void *)0); // expected-warning {{static_cast between pointer-to-function and pointer-to-object is a Microsoft extension}}
314 void (*PR23733_2)() = FnPtrTy((void *)0);
315 void (*PR23733_3)() = (FnPtrTy)((void *)0);
316 void (*PR23733_4)() = reinterpret_cast<FnPtrTy>((void *)0);
317 
318 long function_prototype(int a);
319 long (*function_ptr)(int a);
320 
function_to_voidptr_conv()321 void function_to_voidptr_conv() {
322   void *a1 = function_prototype;  // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
323   void *a2 = &function_prototype; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
324   void *a3 = function_ptr;        // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
325 }
326 
327 namespace member_lookup {
328 
329 template<typename T>
330 struct ConfuseLookup {
331   T* m_val;
332   struct m_val {
333     static size_t ms_test;
334   };
335 };
336 
337 // Microsoft mode allows explicit constructor calls
338 // This could confuse name lookup in cases such as this
339 template<typename T>
340 size_t ConfuseLookup<T>::m_val::ms_test
341   = size_t(&(char&)(reinterpret_cast<ConfuseLookup<T>*>(0)->m_val));
342 
instantiate()343 void instantiate() { ConfuseLookup<int>::m_val::ms_test = 1; }
344 }
345 
346 
347 // Microsoft doesn't validate exception specification.
348 namespace microsoft_exception_spec {
349 
350 void foo(); // expected-note {{previous declaration}}
351 void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
352 
353 void r6() throw(...); // expected-note {{previous declaration}}
354 void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
355 
356 struct Base {
357   virtual void f2();
358   virtual void f3() throw(...);
359 };
360 
361 struct Derived : Base {
362   virtual void f2() throw(...);
363   virtual void f3();
364 };
365 
366 class A {
367   virtual ~A() throw();
368 #if __cplusplus <= 199711L
369   // expected-note@-2 {{overridden virtual function is here}}
370 #endif
371 };
372 
373 class B : public A {
374   virtual ~B();
375 #if __cplusplus <= 199711L
376   // expected-warning@-2 {{exception specification of overriding function is more lax than base version}}
377 #endif
378 };
379 
380 }
381 
382 namespace PR25265 {
383 struct S {
384   int fn() throw(); // expected-note {{previous declaration is here}}
385 };
386 
fn()387 int S::fn() { return 0; } // expected-warning {{is missing exception specification}}
388 }
389 
390 namespace PR43265 {
391 template <int N> // expected-note {{template parameter is declared here}}
392 struct Foo {
393   static const int N = 42; // expected-warning {{declaration of 'N' shadows template parameter}}
394 };
395 }
396 
397 namespace Inner_Outer_same_template_param_name {
398 template <typename T> // expected-note {{template parameter is declared here}}
399 struct Outmost {
400   template <typename T> // expected-warning {{declaration of 'T' shadows template parameter}}
401   struct Inner {
fInner_Outer_same_template_param_name::Outmost::Inner402     void f() {
403       T *var;
404     }
405   };
406 };
407 }
408