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