blob: fe8e8f77accbeefd3f6dadfd2f71f0c045c15f2c [file] [log] [blame]
David Majnemer28aae9c2015-03-18 04:15:23 +00001// 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
Francois Pichet08d2fa02011-09-18 21:37:37 +00003
David Majnemeraaf2b842015-03-18 07:53:18 +00004#if defined(_HAS_CHAR16_T_LANGUAGE_SUPPORT) && _HAS_CHAR16_T_LANGUAGE_SUPPORT
David Majnemer28aae9c2015-03-18 04:15:23 +00005char16_t x;
6char32_t y;
David Majnemer28aae9c2015-03-18 04:15:23 +00007#else
Francois Pichet0e2b8432012-07-22 11:32:41 +00008typedef unsigned short char16_t;
9typedef unsigned int char32_t;
David Majnemeraaf2b842015-03-18 07:53:18 +000010#endif
11
David Majnemeraaf2b842015-03-18 07:53:18 +000012_Atomic(int) z;
David Majnemer51fd8a02015-07-22 23:46:18 +000013template <typename T>
14struct _Atomic {
15 _Atomic() {}
16 ~_Atomic() {}
17};
18template <typename T>
19struct atomic : _Atomic<T> {
20 typedef _Atomic<T> TheBase;
21 TheBase field;
22};
23_Atomic(int) alpha;
Francois Pichet08d2fa02011-09-18 21:37:37 +000024
Francois Pichetf5b24e02012-07-22 15:10:57 +000025typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
26
Francois Pichet08d2fa02011-09-18 21:37:37 +000027namespace ms_conversion_rules {
28
29void f(float a);
30void f(int a);
31
32void test()
33{
34 long a = 0;
35 f((long)0);
36 f(a);
37}
38
39}
40
Francois Pichet39cba532011-09-18 21:48:27 +000041
Alp Tokerab1b1dc2014-01-05 06:38:18 +000042namespace ms_predefined_types {
Alp Toker8db6e7a2014-01-05 06:38:57 +000043 // ::type_info is a built-in forward class declaration.
Alp Tokerab1b1dc2014-01-05 06:38:18 +000044 void f(const type_info &a);
David Majnemer1de36912014-01-14 06:19:35 +000045 void f(size_t);
Alp Tokerab1b1dc2014-01-05 06:38:18 +000046}
47
Francois Pichet39cba532011-09-18 21:48:27 +000048
49namespace ms_protected_scope {
50 struct C { C(); };
51
52 int jump_over_variable_init(bool b) {
53 if (b)
Richard Smith091405d2014-09-06 00:24:58 +000054 goto foo; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
Francois Pichet39cba532011-09-18 21:48:27 +000055 C c; // expected-note {{jump bypasses variable initialization}}
56 foo:
57 return 1;
58 }
59
60struct Y {
61 ~Y();
62};
63
64void jump_over_var_with_dtor() {
Richard Smith091405d2014-09-06 00:24:58 +000065 goto end; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}}
Richard Smithfe2750d2011-10-20 21:42:12 +000066 Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
Francois Pichet39cba532011-09-18 21:48:27 +000067 end:
68 ;
69}
70
71 void jump_over_variable_case(int c) {
72 switch (c) {
73 case 0:
74 int x = 56; // expected-note {{jump bypasses variable initialization}}
Richard Smith091405d2014-09-06 00:24:58 +000075 case 1: // expected-error {{cannot jump}}
Francois Pichet39cba532011-09-18 21:48:27 +000076 x = 10;
77 }
78 }
79
80
81void exception_jump() {
Richard Smith091405d2014-09-06 00:24:58 +000082 goto l2; // expected-error {{cannot jump}}
Francois Pichet39cba532011-09-18 21:48:27 +000083 try { // expected-note {{jump bypasses initialization of try block}}
84 l2: ;
85 } catch(int) {
86 }
87}
88
89int jump_over_indirect_goto() {
90 static void *ps[] = { &&a0 };
Richard Smith091405d2014-09-06 00:24:58 +000091 goto *&&a0; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
Francois Pichet39cba532011-09-18 21:48:27 +000092 int a = 3; // expected-note {{jump bypasses variable initialization}}
93 a0:
94 return 0;
95}
96
97}
98
Nico Weber323076f2012-01-23 04:01:33 +000099namespace PR11826 {
100 struct pair {
101 pair(int v) { }
102 void operator=(pair&& rhs) { }
103 };
104 void f() {
105 pair p0(3);
106 pair p = p0;
107 }
108}
Francois Pichet39cba532011-09-18 21:48:27 +0000109
Nico Weber323076f2012-01-23 04:01:33 +0000110namespace PR11826_for_symmetry {
111 struct pair {
112 pair(int v) { }
113 pair(pair&& rhs) { }
114 };
115 void f() {
116 pair p0(3);
117 pair p(4);
118 p = p0;
119 }
120}
Francois Pichet39cba532011-09-18 21:48:27 +0000121
Nico Weber33a362e2012-01-23 04:08:13 +0000122namespace ms_using_declaration_bug {
123
124class A {
125public:
126 int f();
127};
128
129class B : public A {
130private:
131 using A::f;
Reid Kleckner42063b02014-02-08 02:40:20 +0000132 void g() {
133 f(); // no diagnostic
134 }
Nico Weber33a362e2012-01-23 04:08:13 +0000135};
136
137class C : public B {
138private:
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
Alp Toker0abb0572014-01-18 00:59:32 +0000144namespace 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 }
151 void f() {
152 N::S s1;
153 S s2;
154 }
155 void g() {
156 struct S; // expected-note {{forward declaration of 'S'}}
157 S s3; // expected-error {{variable has incomplete type 'S'}}
158 }
159 void h() {
160 using ::using_tag_redeclaration::S;
161 struct S {}; // expected-error {{redefinition of 'S'}}
162 }
163}
164
Nico Weber33a362e2012-01-23 04:08:13 +0000165
166namespace MissingTypename {
167
168template<class T> class A {
169public:
170 typedef int TYPE;
171};
172
173template<class T> class B {
174public:
175 typedef int TYPE;
176};
177
178
179template<class T, class U>
180class C : private A<T>, public B<U> {
181public:
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
196class D {
197public:
198 typedef int Type;
199};
200
201template <class T>
202void 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
207template void function_missing_typename<D>(const D::Type param);
208
209}
210
Francois Pichet2056a692012-01-21 23:26:50 +0000211enum 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};
Nico Weber33a362e2012-01-23 04:08:13 +0000216
217
Nico Weber58829272012-01-23 05:50:57 +0000218namespace PR11791 {
219 template<class _Ty>
220 void del(_Ty *_Ptr) {
221 _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
222 }
223
224 void f() {
225 int* a = 0;
226 del((void*)a); // expected-note {{in instantiation of function template specialization}}
227 }
228}
Reid Klecknera5eef142013-11-12 02:22:34 +0000229
230namespace 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
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}