blob: a3b96da448cbfba29d2022027b10d5df9957643e [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;
Francois Pichet08d2fa02011-09-18 21:37:37 +00006
Francois Pichetf5b24e02012-07-22 15:10:57 +00007typename decltype(3) a; // expected-warning {{expected a qualified name after 'typename'}}
8
Francois Pichet08d2fa02011-09-18 21:37:37 +00009namespace ms_conversion_rules {
10
11void f(float a);
12void f(int a);
13
14void test()
15{
16 long a = 0;
17 f((long)0);
18 f(a);
19}
20
21}
22
Francois Pichet39cba532011-09-18 21:48:27 +000023
Alp Tokerab1b1dc2014-01-05 06:38:18 +000024namespace ms_predefined_types {
Alp Toker8db6e7a2014-01-05 06:38:57 +000025 // ::type_info is a built-in forward class declaration.
Alp Tokerab1b1dc2014-01-05 06:38:18 +000026 void f(const type_info &a);
David Majnemer1de36912014-01-14 06:19:35 +000027 void f(size_t);
Alp Tokerab1b1dc2014-01-05 06:38:18 +000028}
29
Francois Pichet39cba532011-09-18 21:48:27 +000030
31namespace ms_protected_scope {
32 struct C { C(); };
33
34 int jump_over_variable_init(bool b) {
35 if (b)
Richard Trieu553b2b22011-12-15 00:38:15 +000036 goto foo; // expected-warning {{goto into protected scope}}
Francois Pichet39cba532011-09-18 21:48:27 +000037 C c; // expected-note {{jump bypasses variable initialization}}
38 foo:
39 return 1;
40 }
41
42struct Y {
43 ~Y();
44};
45
46void jump_over_var_with_dtor() {
47 goto end; // expected-warning{{goto into protected scope}}
Richard Smithfe2750d2011-10-20 21:42:12 +000048 Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
Francois Pichet39cba532011-09-18 21:48:27 +000049 end:
50 ;
51}
52
53 void jump_over_variable_case(int c) {
54 switch (c) {
55 case 0:
56 int x = 56; // expected-note {{jump bypasses variable initialization}}
57 case 1: // expected-error {{switch case is in protected scope}}
58 x = 10;
59 }
60 }
61
62
63void exception_jump() {
Richard Trieu553b2b22011-12-15 00:38:15 +000064 goto l2; // expected-error {{goto into protected scope}}
Francois Pichet39cba532011-09-18 21:48:27 +000065 try { // expected-note {{jump bypasses initialization of try block}}
66 l2: ;
67 } catch(int) {
68 }
69}
70
71int jump_over_indirect_goto() {
72 static void *ps[] = { &&a0 };
73 goto *&&a0; // expected-warning {{goto into protected scope}}
74 int a = 3; // expected-note {{jump bypasses variable initialization}}
75 a0:
76 return 0;
77}
78
79}
80
Nico Weber323076f2012-01-23 04:01:33 +000081namespace PR11826 {
82 struct pair {
83 pair(int v) { }
84 void operator=(pair&& rhs) { }
85 };
86 void f() {
87 pair p0(3);
88 pair p = p0;
89 }
90}
Francois Pichet39cba532011-09-18 21:48:27 +000091
Nico Weber323076f2012-01-23 04:01:33 +000092namespace PR11826_for_symmetry {
93 struct pair {
94 pair(int v) { }
95 pair(pair&& rhs) { }
96 };
97 void f() {
98 pair p0(3);
99 pair p(4);
100 p = p0;
101 }
102}
Francois Pichet39cba532011-09-18 21:48:27 +0000103
Nico Weber33a362e2012-01-23 04:08:13 +0000104namespace ms_using_declaration_bug {
105
106class A {
107public:
108 int f();
109};
110
111class B : public A {
112private:
113 using A::f;
Reid Kleckner42063b02014-02-08 02:40:20 +0000114 void g() {
115 f(); // no diagnostic
116 }
Nico Weber33a362e2012-01-23 04:08:13 +0000117};
118
119class C : public B {
120private:
121 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}}
122};
123
124}
125
Alp Toker0abb0572014-01-18 00:59:32 +0000126namespace using_tag_redeclaration
127{
128 struct S;
129 namespace N {
130 using ::using_tag_redeclaration::S;
131 struct S {}; // expected-note {{previous definition is here}}
132 }
133 void f() {
134 N::S s1;
135 S s2;
136 }
137 void g() {
138 struct S; // expected-note {{forward declaration of 'S'}}
139 S s3; // expected-error {{variable has incomplete type 'S'}}
140 }
141 void h() {
142 using ::using_tag_redeclaration::S;
143 struct S {}; // expected-error {{redefinition of 'S'}}
144 }
145}
146
Nico Weber33a362e2012-01-23 04:08:13 +0000147
148namespace MissingTypename {
149
150template<class T> class A {
151public:
152 typedef int TYPE;
153};
154
155template<class T> class B {
156public:
157 typedef int TYPE;
158};
159
160
161template<class T, class U>
162class C : private A<T>, public B<U> {
163public:
164 typedef A<T> Base1;
165 typedef B<U> Base2;
166 typedef A<U> Base3;
167
168 A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
169 Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
170
171 B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
172 Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
173
174 A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
175 Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
176 };
177
178class D {
179public:
180 typedef int Type;
181};
182
183template <class T>
184void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
185{
186 const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
187}
188
189template void function_missing_typename<D>(const D::Type param);
190
191}
192
Francois Pichet2056a692012-01-21 23:26:50 +0000193enum ENUM2 {
194 ENUM2_a = (enum ENUM2) 4,
195 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
196 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
197};
Nico Weber33a362e2012-01-23 04:08:13 +0000198
199
Nico Weber58829272012-01-23 05:50:57 +0000200namespace PR11791 {
201 template<class _Ty>
202 void del(_Ty *_Ptr) {
203 _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
204 }
205
206 void f() {
207 int* a = 0;
208 del((void*)a); // expected-note {{in instantiation of function template specialization}}
209 }
210}
Reid Klecknera5eef142013-11-12 02:22:34 +0000211
212namespace IntToNullPtrConv {
213 struct Foo {
214 static const int ZERO = 0;
215 typedef void (Foo::*MemberFcnPtr)();
216 };
217
218 struct Bar {
219 const Foo::MemberFcnPtr pB;
220 };
221
222 Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
223
224 template<int N> int *get_n() { return N; } // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
225 int *g_nullptr = get_n<0>(); // expected-note {{in instantiation of function template specialization}}
226}