xref: /llvm-project/clang/test/SemaCXX/MicrosoftCompatibility.cpp (revision 28aae9c29b6dd740c4d8da4b7019f2b83bc446b2)
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 _MSC_VER >= 1900
5 char16_t x;
6 char32_t y;
7 _Atomic(int) z;
8 #else
9 typedef unsigned short char16_t;
10 typedef unsigned int char32_t;
11 struct _Atomic {};
12 #endif
13 
14 typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
15 
16 namespace ms_conversion_rules {
17 
18 void f(float a);
19 void f(int a);
20 
21 void test()
22 {
23     long a = 0;
24     f((long)0);
25 	f(a);
26 }
27 
28 }
29 
30 
31 namespace ms_predefined_types {
32   // ::type_info is a built-in forward class declaration.
33   void f(const type_info &a);
34   void f(size_t);
35 }
36 
37 
38 namespace ms_protected_scope {
39   struct C { C(); };
40 
41   int jump_over_variable_init(bool b) {
42     if (b)
43       goto foo; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
44     C c; // expected-note {{jump bypasses variable initialization}}
45   foo:
46     return 1;
47   }
48 
49 struct Y {
50   ~Y();
51 };
52 
53 void jump_over_var_with_dtor() {
54   goto end; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}}
55   Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
56  end:
57     ;
58 }
59 
60   void jump_over_variable_case(int c) {
61     switch (c) {
62     case 0:
63       int x = 56; // expected-note {{jump bypasses variable initialization}}
64     case 1:       // expected-error {{cannot jump}}
65       x = 10;
66     }
67   }
68 
69 
70 void exception_jump() {
71   goto l2; // expected-error {{cannot jump}}
72   try { // expected-note {{jump bypasses initialization of try block}}
73      l2: ;
74   } catch(int) {
75   }
76 }
77 
78 int jump_over_indirect_goto() {
79   static void *ps[] = { &&a0 };
80   goto *&&a0; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
81   int a = 3; // expected-note {{jump bypasses variable initialization}}
82  a0:
83   return 0;
84 }
85 
86 }
87 
88 namespace PR11826 {
89   struct pair {
90     pair(int v) { }
91     void operator=(pair&& rhs) { }
92   };
93   void f() {
94     pair p0(3);
95     pair p = p0;
96   }
97 }
98 
99 namespace PR11826_for_symmetry {
100   struct pair {
101     pair(int v) { }
102     pair(pair&& rhs) { }
103   };
104   void f() {
105     pair p0(3);
106     pair p(4);
107     p = p0;
108   }
109 }
110 
111 namespace ms_using_declaration_bug {
112 
113 class A {
114 public:
115   int f();
116 };
117 
118 class B : public A {
119 private:
120   using A::f;
121   void g() {
122     f(); // no diagnostic
123   }
124 };
125 
126 class C : public B {
127 private:
128   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}}
129 };
130 
131 }
132 
133 namespace using_tag_redeclaration
134 {
135   struct S;
136   namespace N {
137     using ::using_tag_redeclaration::S;
138     struct S {}; // expected-note {{previous definition is here}}
139   }
140   void f() {
141     N::S s1;
142     S s2;
143   }
144   void g() {
145     struct S; // expected-note {{forward declaration of 'S'}}
146     S s3; // expected-error {{variable has incomplete type 'S'}}
147   }
148   void h() {
149     using ::using_tag_redeclaration::S;
150     struct S {}; // expected-error {{redefinition of 'S'}}
151   }
152 }
153 
154 
155 namespace MissingTypename {
156 
157 template<class T> class A {
158 public:
159 	 typedef int TYPE;
160 };
161 
162 template<class T> class B {
163 public:
164 	 typedef int TYPE;
165 };
166 
167 
168 template<class T, class U>
169 class C : private A<T>, public B<U> {
170 public:
171    typedef A<T> Base1;
172    typedef B<U> Base2;
173    typedef A<U> Base3;
174 
175    A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
176    Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
177 
178    B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
179    Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
180 
181    A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
182    Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
183  };
184 
185 class D {
186 public:
187     typedef int Type;
188 };
189 
190 template <class T>
191 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
192 {
193     const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
194 }
195 
196 template void function_missing_typename<D>(const D::Type param);
197 
198 }
199 
200 enum ENUM2 {
201 	ENUM2_a = (enum ENUM2) 4,
202 	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
203 	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
204 };
205 
206 
207 namespace PR11791 {
208   template<class _Ty>
209   void del(_Ty *_Ptr) {
210     _Ptr->~_Ty();  // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
211   }
212 
213   void f() {
214     int* a = 0;
215     del((void*)a);  // expected-note {{in instantiation of function template specialization}}
216   }
217 }
218 
219 namespace IntToNullPtrConv {
220   struct Foo {
221     static const int ZERO = 0;
222     typedef void (Foo::*MemberFcnPtr)();
223   };
224 
225   struct Bar {
226     const Foo::MemberFcnPtr pB;
227   };
228 
229   Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
230 
231   template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
232   int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
233 }
234