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.00
2 // 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
3 
4 #if defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT
5 char16_t x;
6 char32_t y;
7 #else
8 typedef unsigned short char16_t;
9 typedef unsigned int char32_t;
10 #endif
11 
12 _Atomic(int) z;
13 template <typename T>
14 struct _Atomic {
_Atomic_Atomic15   _Atomic() {}
~_Atomic_Atomic16   ~_Atomic() {}
17 };
18 template <typename T>
19 struct atomic : _Atomic<T> {
20   typedef _Atomic<T> TheBase;
21   TheBase field;
22 };
23 _Atomic(int) alpha;
24 
25 typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
26 
27 namespace ms_conversion_rules {
28 
29 void f(float a);
30 void f(int a);
31 
test()32 void test()
33 {
34     long a = 0;
35     f((long)0);
36 	f(a);
37 }
38 
39 }
40 
41 
42 namespace ms_predefined_types {
43   // ::type_info is a built-in forward class declaration.
44   void f(const type_info &a);
45   void f(size_t);
46 }
47 
48 
49 namespace ms_protected_scope {
50   struct C { C(); };
51 
jump_over_variable_init(bool b)52   int jump_over_variable_init(bool b) {
53     if (b)
54       goto foo; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
55     C c; // expected-note {{jump bypasses variable initialization}}
56   foo:
57     return 1;
58   }
59 
60 struct Y {
61   ~Y();
62 };
63 
jump_over_var_with_dtor()64 void jump_over_var_with_dtor() {
65   goto end; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}}
66   Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
67  end:
68     ;
69 }
70 
jump_over_variable_case(int c)71   void jump_over_variable_case(int c) {
72     switch (c) {
73     case 0:
74       int x = 56; // expected-note {{jump bypasses variable initialization}}
75     case 1:       // expected-error {{cannot jump}}
76       x = 10;
77     }
78   }
79 
80 
exception_jump()81 void exception_jump() {
82   goto l2; // expected-error {{cannot jump}}
83   try { // expected-note {{jump bypasses initialization of try block}}
84      l2: ;
85   } catch(int) {
86   }
87 }
88 
jump_over_indirect_goto()89 int jump_over_indirect_goto() {
90   static void *ps[] = { &&a0 };
91   goto *&&a0; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
92   int a = 3; // expected-note {{jump bypasses variable initialization}}
93  a0:
94   return 0;
95 }
96 
97 }
98 
99 namespace PR11826 {
100   struct pair {
pairPR11826::pair101     pair(int v) { }
102 #if _MSC_VER >= 1900
operator =PR11826::pair103     void operator=(pair&& rhs) { } // expected-note {{copy constructor is implicitly deleted because 'pair' has a user-declared move assignment operator}}
104 #else
operator =PR11826::pair105     void operator=(pair&& rhs) { }
106 #endif
107   };
f()108   void f() {
109     pair p0(3);
110 #if _MSC_VER >= 1900
111     pair p = p0; // expected-error {{call to implicitly-deleted copy constructor of 'PR11826::pair'}}
112 #else
113     pair p = p0;
114 #endif
115   }
116 }
117 
118 namespace PR11826_for_symmetry {
119   struct pair {
pairPR11826_for_symmetry::pair120     pair(int v) { }
121 #if _MSC_VER >= 1900
pairPR11826_for_symmetry::pair122     pair(pair&& rhs) { } // expected-note {{copy assignment operator is implicitly deleted because 'pair' has a user-declared move constructor}}
123 #else
pairPR11826_for_symmetry::pair124     pair(pair&& rhs) { }
125 #endif
126   };
f()127   void f() {
128     pair p0(3);
129     pair p(4);
130 #if _MSC_VER >= 1900
131     p = p0; // expected-error {{object of type 'PR11826_for_symmetry::pair' cannot be assigned because its copy assignment operator is implicitly deleted}}
132 #else
133     p = p0;
134 #endif
135   }
136 }
137 
138 namespace ms_using_declaration_bug {
139 
140 class A {
141 public:
142   int f();
143 };
144 
145 class B : public A {
146 private:
147   using A::f;
g()148   void g() {
149     f(); // no diagnostic
150   }
151 };
152 
153 class C : public B {
154 private:
155   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}}
156 };
157 
158 }
159 
160 namespace using_tag_redeclaration
161 {
162   struct S;
163   namespace N {
164     using ::using_tag_redeclaration::S;
165     struct S {}; // expected-note {{previous definition is here}}
166   }
f()167   void f() {
168     N::S s1;
169     S s2;
170   }
g()171   void g() {
172     struct S; // expected-note {{forward declaration of 'S'}}
173     S s3; // expected-error {{variable has incomplete type 'S'}}
174   }
h()175   void h() {
176     using ::using_tag_redeclaration::S;
177     struct S {}; // expected-error {{redefinition of 'S'}}
178   }
179 }
180 
181 
182 namespace MissingTypename {
183 
184 template<class T> class A {
185 public:
186 	 typedef int TYPE;
187 };
188 
189 template<class T> class B {
190 public:
191 	 typedef int TYPE;
192 };
193 
194 
195 template<class T, class U>
196 class C : private A<T>, public B<U> {
197 public:
198    typedef A<T> Base1;
199    typedef B<U> Base2;
200    typedef A<U> Base3;
201 
202    A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
203    Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
204 
205    B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
206    Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
207 
208    A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
209    Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
210  };
211 
212 class D {
213 public:
214     typedef int Type;
215 };
216 
217 template <class T>
function_missing_typename(const T::Type param)218 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
219 {
220     const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
221 }
222 
223 template void function_missing_typename<D>(const D::Type param);
224 
225 }
226 
227 //MSVC allows forward enum declaration
228 enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
229 ENUM *var = 0;
230 ENUM var2 = (ENUM)3;
231 enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
232 
233 enum ENUM1 { kA };
234 enum ENUM1;  // This way round is fine.
235 
236 enum ENUM2 {
237 	ENUM2_a = (enum ENUM2) 4,
238 	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
239 	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
240 };
241 
242 namespace NsEnumForwardDecl {
243   enum E *p; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
244   extern E e;
245 }
246 // Clang used to complain that NsEnumForwardDecl::E was undeclared below.
247 NsEnumForwardDecl::E NsEnumForwardDecl_e;
248 namespace NsEnumForwardDecl {
249   extern E e;
250 }
251 
252 namespace PR11791 {
253   template<class _Ty>
del(_Ty * _Ptr)254   void del(_Ty *_Ptr) {
255     _Ptr->~_Ty();  // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
256   }
257 
f()258   void f() {
259     int* a = 0;
260     del((void*)a);  // expected-note {{in instantiation of function template specialization}}
261   }
262 }
263 
264 namespace IntToNullPtrConv {
265   struct Foo {
266     static const int ZERO = 0;
267     typedef void (Foo::*MemberFcnPtr)();
268   };
269 
270   struct Bar {
271     const Foo::MemberFcnPtr pB;
272   };
273 
274   Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
275 
get_n()276   template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
277   int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
278 }
279 
280 namespace signed_hex_i64 {
281 void f(long long);
282 void f(int);
g()283 void g() {
284   // This is an ambiguous call in standard C++.
285   // This calls f(long long) in Microsoft mode because LL is always signed.
286   f(0xffffffffffffffffLL);
287   f(0xffffffffffffffffi64);
288 }
289 }
290 
291 typedef void (*FnPtrTy)();
292 void (*PR23733_1)() = static_cast<FnPtrTy>((void *)0); // expected-warning {{static_cast between pointer-to-function and pointer-to-object is a Microsoft extension}}
293 void (*PR23733_2)() = FnPtrTy((void *)0);
294 void (*PR23733_3)() = (FnPtrTy)((void *)0);
295 void (*PR23733_4)() = reinterpret_cast<FnPtrTy>((void *)0);
296 
297 long function_prototype(int a);
298 long (*function_ptr)(int a);
299 
function_to_voidptr_conv()300 void function_to_voidptr_conv() {
301   void *a1 = function_prototype;  // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
302   void *a2 = &function_prototype; // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
303   void *a3 = function_ptr;        // expected-warning {{implicit conversion between pointer-to-function and pointer-to-object is a Microsoft extension}}
304 }
305 
306 namespace member_lookup {
307 
308 template<typename T>
309 struct ConfuseLookup {
310   T* m_val;
311   struct m_val {
312     static size_t ms_test;
313   };
314 };
315 
316 // Microsoft mode allows explicit constructor calls
317 // This could confuse name lookup in cases such as this
318 template<typename T>
319 size_t ConfuseLookup<T>::m_val::ms_test
320   = size_t(&(char&)(reinterpret_cast<ConfuseLookup<T>*>(0)->m_val));
321 
instantiate()322 void instantiate() { ConfuseLookup<int>::m_val::ms_test = 1; }
323 }
324 
325