blob: 3097b7da107e2593f373937b3a0f95fca9b91f8d [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 {
25 // ::type_info is predeclared with forward class declartion
26 void f(const type_info &a);
27}
28
Francois Pichet39cba532011-09-18 21:48:27 +000029
30namespace ms_protected_scope {
31 struct C { C(); };
32
33 int jump_over_variable_init(bool b) {
34 if (b)
Richard Trieu553b2b22011-12-15 00:38:15 +000035 goto foo; // expected-warning {{goto into protected scope}}
Francois Pichet39cba532011-09-18 21:48:27 +000036 C c; // expected-note {{jump bypasses variable initialization}}
37 foo:
38 return 1;
39 }
40
41struct Y {
42 ~Y();
43};
44
45void jump_over_var_with_dtor() {
46 goto end; // expected-warning{{goto into protected scope}}
Richard Smithfe2750d2011-10-20 21:42:12 +000047 Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
Francois Pichet39cba532011-09-18 21:48:27 +000048 end:
49 ;
50}
51
52 void jump_over_variable_case(int c) {
53 switch (c) {
54 case 0:
55 int x = 56; // expected-note {{jump bypasses variable initialization}}
56 case 1: // expected-error {{switch case is in protected scope}}
57 x = 10;
58 }
59 }
60
61
62void exception_jump() {
Richard Trieu553b2b22011-12-15 00:38:15 +000063 goto l2; // expected-error {{goto into protected scope}}
Francois Pichet39cba532011-09-18 21:48:27 +000064 try { // expected-note {{jump bypasses initialization of try block}}
65 l2: ;
66 } catch(int) {
67 }
68}
69
70int jump_over_indirect_goto() {
71 static void *ps[] = { &&a0 };
72 goto *&&a0; // expected-warning {{goto into protected scope}}
73 int a = 3; // expected-note {{jump bypasses variable initialization}}
74 a0:
75 return 0;
76}
77
78}
79
Nico Weber323076f2012-01-23 04:01:33 +000080namespace PR11826 {
81 struct pair {
82 pair(int v) { }
83 void operator=(pair&& rhs) { }
84 };
85 void f() {
86 pair p0(3);
87 pair p = p0;
88 }
89}
Francois Pichet39cba532011-09-18 21:48:27 +000090
Nico Weber323076f2012-01-23 04:01:33 +000091namespace PR11826_for_symmetry {
92 struct pair {
93 pair(int v) { }
94 pair(pair&& rhs) { }
95 };
96 void f() {
97 pair p0(3);
98 pair p(4);
99 p = p0;
100 }
101}
Francois Pichet39cba532011-09-18 21:48:27 +0000102
Nico Weber33a362e2012-01-23 04:08:13 +0000103namespace ms_using_declaration_bug {
104
105class A {
106public:
107 int f();
108};
109
110class B : public A {
111private:
112 using A::f;
113};
114
115class C : public B {
116private:
117 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}}
118};
119
120}
121
122
123namespace MissingTypename {
124
125template<class T> class A {
126public:
127 typedef int TYPE;
128};
129
130template<class T> class B {
131public:
132 typedef int TYPE;
133};
134
135
136template<class T, class U>
137class C : private A<T>, public B<U> {
138public:
139 typedef A<T> Base1;
140 typedef B<U> Base2;
141 typedef A<U> Base3;
142
143 A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
144 Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
145
146 B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
147 Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
148
149 A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
150 Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
151 };
152
153class D {
154public:
155 typedef int Type;
156};
157
158template <class T>
159void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
160{
161 const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
162}
163
164template void function_missing_typename<D>(const D::Type param);
165
166}
167
Francois Pichet2056a692012-01-21 23:26:50 +0000168enum ENUM2 {
169 ENUM2_a = (enum ENUM2) 4,
170 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
171 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
172};
Nico Weber33a362e2012-01-23 04:08:13 +0000173
174
Nico Weber58829272012-01-23 05:50:57 +0000175namespace PR11791 {
176 template<class _Ty>
177 void del(_Ty *_Ptr) {
178 _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
179 }
180
181 void f() {
182 int* a = 0;
183 del((void*)a); // expected-note {{in instantiation of function template specialization}}
184 }
185}
Reid Klecknera5eef142013-11-12 02:22:34 +0000186
187namespace IntToNullPtrConv {
188 struct Foo {
189 static const int ZERO = 0;
190 typedef void (Foo::*MemberFcnPtr)();
191 };
192
193 struct Bar {
194 const Foo::MemberFcnPtr pB;
195 };
196
197 Bar g_bar = { (Foo::MemberFcnPtr)Foo::ZERO };
198
199 template<int N> int *get_n() { return N; } // expected-warning {{expression which evaluates to zero treated as a null pointer constant}}
200 int *g_nullptr = get_n<0>(); // expected-note {{in instantiation of function template specialization}}
201}