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