blob: fb7d9751d1a5a4ea58d037aaf64a9a9e548a0bb2 [file] [log] [blame]
Francois Pichet2056a692012-01-21 23:26:50 +00001// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -Wmicrosoft -verify -fms-compatibility -fexceptions -fcxx-exceptions
Francois Pichet08d2fa02011-09-18 21:37:37 +00002
3
Francois Pichet0e2b8432012-07-22 11:32:41 +00004typedef unsigned short char16_t;
5typedef unsigned int char32_t;
David Majnemer75991302014-03-04 22:07:09 +00006struct _Atomic {};
Francois Pichet08d2fa02011-09-18 21:37:37 +00007
Francois Pichetf5b24e02012-07-22 15:10:57 +00008typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
9
Francois Pichet08d2fa02011-09-18 21:37:37 +000010namespace ms_conversion_rules {
11
12void f(float a);
13void f(int a);
14
15void test()
16{
17 long a = 0;
18 f((long)0);
19 f(a);
20}
21
22}
23
Francois Pichet39cba532011-09-18 21:48:27 +000024
Alp Tokerab1b1dc2014-01-05 06:38:18 +000025namespace ms_predefined_types {
Alp Toker8db6e7a2014-01-05 06:38:57 +000026 // ::type_info is a built-in forward class declaration.
Alp Tokerab1b1dc2014-01-05 06:38:18 +000027 void f(const type_info &a);
David Majnemer1de36912014-01-14 06:19:35 +000028 void f(size_t);
Alp Tokerab1b1dc2014-01-05 06:38:18 +000029}
30
Francois Pichet39cba532011-09-18 21:48:27 +000031
32namespace ms_protected_scope {
33 struct C { C(); };
34
35 int jump_over_variable_init(bool b) {
36 if (b)
Richard Trieu553b2b22011-12-15 00:38:15 +000037 goto foo; // expected-warning {{goto into protected scope}}
Francois Pichet39cba532011-09-18 21:48:27 +000038 C c; // expected-note {{jump bypasses variable initialization}}
39 foo:
40 return 1;
41 }
42
43struct Y {
44 ~Y();
45};
46
47void jump_over_var_with_dtor() {
48 goto end; // expected-warning{{goto into protected scope}}
Richard Smithfe2750d2011-10-20 21:42:12 +000049 Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
Francois Pichet39cba532011-09-18 21:48:27 +000050 end:
51 ;
52}
53
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 {{switch case is in protected scope}}
59 x = 10;
60 }
61 }
62
63
64void exception_jump() {
Richard Trieu553b2b22011-12-15 00:38:15 +000065 goto l2; // expected-error {{goto into protected scope}}
Francois Pichet39cba532011-09-18 21:48:27 +000066 try { // expected-note {{jump bypasses initialization of try block}}
67 l2: ;
68 } catch(int) {
69 }
70}
71
72int jump_over_indirect_goto() {
73 static void *ps[] = { &&a0 };
74 goto *&&a0; // expected-warning {{goto into protected scope}}
75 int a = 3; // expected-note {{jump bypasses variable initialization}}
76 a0:
77 return 0;
78}
79
80}
81
Nico Weber323076f2012-01-23 04:01:33 +000082namespace PR11826 {
83 struct pair {
84 pair(int v) { }
85 void operator=(pair&& rhs) { }
86 };
87 void f() {
88 pair p0(3);
89 pair p = p0;
90 }
91}
Francois Pichet39cba532011-09-18 21:48:27 +000092
Nico Weber323076f2012-01-23 04:01:33 +000093namespace PR11826_for_symmetry {
94 struct pair {
95 pair(int v) { }
96 pair(pair&& rhs) { }
97 };
98 void f() {
99 pair p0(3);
100 pair p(4);
101 p = p0;
102 }
103}
Francois Pichet39cba532011-09-18 21:48:27 +0000104
Nico Weber33a362e2012-01-23 04:08:13 +0000105namespace ms_using_declaration_bug {
106
107class A {
108public:
109 int f();
110};
111
112class B : public A {
113private:
114 using A::f;
Reid Kleckner42063b02014-02-08 02:40:20 +0000115 void g() {
116 f(); // no diagnostic
117 }
Nico Weber33a362e2012-01-23 04:08:13 +0000118};
119
120class C : public B {
121private:
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
Alp Toker0abb0572014-01-18 00:59:32 +0000127namespace 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 }
134 void f() {
135 N::S s1;
136 S s2;
137 }
138 void g() {
139 struct S; // expected-note {{forward declaration of 'S'}}
140 S s3; // expected-error {{variable has incomplete type 'S'}}
141 }
142 void h() {
143 using ::using_tag_redeclaration::S;
144 struct S {}; // expected-error {{redefinition of 'S'}}
145 }
146}
147
Nico Weber33a362e2012-01-23 04:08:13 +0000148
149namespace MissingTypename {
150
151template<class T> class A {
152public:
153 typedef int TYPE;
154};
155
156template<class T> class B {
157public:
158 typedef int TYPE;
159};
160
161
162template<class T, class U>
163class C : private A<T>, public B<U> {
164public:
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
179class D {
180public:
181 typedef int Type;
182};
183
184template <class T>
185void 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
190template void function_missing_typename<D>(const D::Type param);
191
192}
193
Francois Pichet2056a692012-01-21 23:26:50 +0000194enum 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};
Nico Weber33a362e2012-01-23 04:08:13 +0000199
200
Nico Weber58829272012-01-23 05:50:57 +0000201namespace PR11791 {
202 template<class _Ty>
203 void del(_Ty *_Ptr) {
204 _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
205 }
206
207 void f() {
208 int* a = 0;
209 del((void*)a); // expected-note {{in instantiation of function template specialization}}
210 }
211}
Reid Klecknera5eef142013-11-12 02:22:34 +0000212
213namespace 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
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}