blob: 1536007a6478f5d5fe93340393cd16f94a008776 [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
12#if _MSC_VER >= 1900
13_Atomic(int) z;
14#else
David Majnemer75991302014-03-04 22:07:09 +000015struct _Atomic {};
David Majnemer28aae9c2015-03-18 04:15:23 +000016#endif
Francois Pichet08d2fa02011-09-18 21:37:37 +000017
Francois Pichetf5b24e02012-07-22 15:10:57 +000018typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
19
Francois Pichet08d2fa02011-09-18 21:37:37 +000020namespace ms_conversion_rules {
21
22void f(float a);
23void f(int a);
24
25void test()
26{
27 long a = 0;
28 f((long)0);
29 f(a);
30}
31
32}
33
Francois Pichet39cba532011-09-18 21:48:27 +000034
Alp Tokerab1b1dc2014-01-05 06:38:18 +000035namespace ms_predefined_types {
Alp Toker8db6e7a2014-01-05 06:38:57 +000036 // ::type_info is a built-in forward class declaration.
Alp Tokerab1b1dc2014-01-05 06:38:18 +000037 void f(const type_info &a);
David Majnemer1de36912014-01-14 06:19:35 +000038 void f(size_t);
Alp Tokerab1b1dc2014-01-05 06:38:18 +000039}
40
Francois Pichet39cba532011-09-18 21:48:27 +000041
42namespace ms_protected_scope {
43 struct C { C(); };
44
45 int jump_over_variable_init(bool b) {
46 if (b)
Richard Smith091405d2014-09-06 00:24:58 +000047 goto foo; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
Francois Pichet39cba532011-09-18 21:48:27 +000048 C c; // expected-note {{jump bypasses variable initialization}}
49 foo:
50 return 1;
51 }
52
53struct Y {
54 ~Y();
55};
56
57void jump_over_var_with_dtor() {
Richard Smith091405d2014-09-06 00:24:58 +000058 goto end; // expected-warning{{jump from this goto statement to its label is a Microsoft extension}}
Richard Smithfe2750d2011-10-20 21:42:12 +000059 Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
Francois Pichet39cba532011-09-18 21:48:27 +000060 end:
61 ;
62}
63
64 void jump_over_variable_case(int c) {
65 switch (c) {
66 case 0:
67 int x = 56; // expected-note {{jump bypasses variable initialization}}
Richard Smith091405d2014-09-06 00:24:58 +000068 case 1: // expected-error {{cannot jump}}
Francois Pichet39cba532011-09-18 21:48:27 +000069 x = 10;
70 }
71 }
72
73
74void exception_jump() {
Richard Smith091405d2014-09-06 00:24:58 +000075 goto l2; // expected-error {{cannot jump}}
Francois Pichet39cba532011-09-18 21:48:27 +000076 try { // expected-note {{jump bypasses initialization of try block}}
77 l2: ;
78 } catch(int) {
79 }
80}
81
82int jump_over_indirect_goto() {
83 static void *ps[] = { &&a0 };
Richard Smith091405d2014-09-06 00:24:58 +000084 goto *&&a0; // expected-warning {{jump from this goto statement to its label is a Microsoft extension}}
Francois Pichet39cba532011-09-18 21:48:27 +000085 int a = 3; // expected-note {{jump bypasses variable initialization}}
86 a0:
87 return 0;
88}
89
90}
91
Nico Weber323076f2012-01-23 04:01:33 +000092namespace PR11826 {
93 struct pair {
94 pair(int v) { }
95 void operator=(pair&& rhs) { }
96 };
97 void f() {
98 pair p0(3);
99 pair p = p0;
100 }
101}
Francois Pichet39cba532011-09-18 21:48:27 +0000102
Nico Weber323076f2012-01-23 04:01:33 +0000103namespace PR11826_for_symmetry {
104 struct pair {
105 pair(int v) { }
106 pair(pair&& rhs) { }
107 };
108 void f() {
109 pair p0(3);
110 pair p(4);
111 p = p0;
112 }
113}
Francois Pichet39cba532011-09-18 21:48:27 +0000114
Nico Weber33a362e2012-01-23 04:08:13 +0000115namespace ms_using_declaration_bug {
116
117class A {
118public:
119 int f();
120};
121
122class B : public A {
123private:
124 using A::f;
Reid Kleckner42063b02014-02-08 02:40:20 +0000125 void g() {
126 f(); // no diagnostic
127 }
Nico Weber33a362e2012-01-23 04:08:13 +0000128};
129
130class C : public B {
131private:
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
Alp Toker0abb0572014-01-18 00:59:32 +0000137namespace 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 }
144 void f() {
145 N::S s1;
146 S s2;
147 }
148 void g() {
149 struct S; // expected-note {{forward declaration of 'S'}}
150 S s3; // expected-error {{variable has incomplete type 'S'}}
151 }
152 void h() {
153 using ::using_tag_redeclaration::S;
154 struct S {}; // expected-error {{redefinition of 'S'}}
155 }
156}
157
Nico Weber33a362e2012-01-23 04:08:13 +0000158
159namespace MissingTypename {
160
161template<class T> class A {
162public:
163 typedef int TYPE;
164};
165
166template<class T> class B {
167public:
168 typedef int TYPE;
169};
170
171
172template<class T, class U>
173class C : private A<T>, public B<U> {
174public:
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
189class D {
190public:
191 typedef int Type;
192};
193
194template <class T>
195void 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
200template void function_missing_typename<D>(const D::Type param);
201
202}
203
Francois Pichet2056a692012-01-21 23:26:50 +0000204enum 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};
Nico Weber33a362e2012-01-23 04:08:13 +0000209
210
Nico Weber58829272012-01-23 05:50:57 +0000211namespace PR11791 {
212 template<class _Ty>
213 void del(_Ty *_Ptr) {
214 _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
215 }
216
217 void f() {
218 int* a = 0;
219 del((void*)a); // expected-note {{in instantiation of function template specialization}}
220 }
221}
Reid Klecknera5eef142013-11-12 02:22:34 +0000222
223namespace 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
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}