• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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) { }
operator =PR11826::pair102     void operator=(pair&& rhs) { }
103   };
f()104   void f() {
105     pair p0(3);
106     pair p = p0;
107   }
108 }
109 
110 namespace PR11826_for_symmetry {
111   struct pair {
pairPR11826_for_symmetry::pair112     pair(int v) { }
pairPR11826_for_symmetry::pair113     pair(pair&& rhs) { }
114   };
f()115   void f() {
116     pair p0(3);
117     pair p(4);
118     p = p0;
119   }
120 }
121 
122 namespace ms_using_declaration_bug {
123 
124 class A {
125 public:
126   int f();
127 };
128 
129 class B : public A {
130 private:
131   using A::f;
g()132   void g() {
133     f(); // no diagnostic
134   }
135 };
136 
137 class C : public B {
138 private:
139   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}}
140 };
141 
142 }
143 
144 namespace using_tag_redeclaration
145 {
146   struct S;
147   namespace N {
148     using ::using_tag_redeclaration::S;
149     struct S {}; // expected-note {{previous definition is here}}
150   }
f()151   void f() {
152     N::S s1;
153     S s2;
154   }
g()155   void g() {
156     struct S; // expected-note {{forward declaration of 'S'}}
157     S s3; // expected-error {{variable has incomplete type 'S'}}
158   }
h()159   void h() {
160     using ::using_tag_redeclaration::S;
161     struct S {}; // expected-error {{redefinition of 'S'}}
162   }
163 }
164 
165 
166 namespace MissingTypename {
167 
168 template<class T> class A {
169 public:
170 	 typedef int TYPE;
171 };
172 
173 template<class T> class B {
174 public:
175 	 typedef int TYPE;
176 };
177 
178 
179 template<class T, class U>
180 class C : private A<T>, public B<U> {
181 public:
182    typedef A<T> Base1;
183    typedef B<U> Base2;
184    typedef A<U> Base3;
185 
186    A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
187    Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
188 
189    B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
190    Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
191 
192    A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
193    Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
194  };
195 
196 class D {
197 public:
198     typedef int Type;
199 };
200 
201 template <class T>
function_missing_typename(const T::Type param)202 void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
203 {
204     const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
205 }
206 
207 template void function_missing_typename<D>(const D::Type param);
208 
209 }
210 
211 enum ENUM2 {
212 	ENUM2_a = (enum ENUM2) 4,
213 	ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
214 	ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
215 };
216 
217 
218 namespace PR11791 {
219   template<class _Ty>
del(_Ty * _Ptr)220   void del(_Ty *_Ptr) {
221     _Ptr->~_Ty();  // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
222   }
223 
f()224   void f() {
225     int* a = 0;
226     del((void*)a);  // expected-note {{in instantiation of function template specialization}}
227   }
228 }
229 
230 namespace IntToNullPtrConv {
231   struct Foo {
232     static const int ZERO = 0;
233     typedef void (Foo::*MemberFcnPtr)();
234   };
235 
236   struct Bar {
237     const Foo::MemberFcnPtr pB;
238   };
239 
240   Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
241 
get_n()242   template<int N> int *get_n() { return N; }   // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
243   int *g_nullptr = get_n<0>();  // expected-note {{in instantiation of function template specialization}}
244 }
245