blob: 74d54ef99417cdec25e8016e4d121e4e44085185 [file] [log] [blame]
Francois Pichet6b6fb4f2012-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 Pichet1c98d622011-09-18 21:37:37 +00002
3
Francois Pichetdfd110c2012-07-22 11:32:41 +00004typedef unsigned short char16_t;
5typedef unsigned int char32_t;
Francois Pichet1c98d622011-09-18 21:37:37 +00006
7namespace ms_conversion_rules {
8
9void f(float a);
10void f(int a);
11
12void test()
13{
14 long a = 0;
15 f((long)0);
16 f(a);
17}
18
19}
20
Francois Pichet8b3c99e2011-09-18 21:48:27 +000021
22
23namespace ms_protected_scope {
24 struct C { C(); };
25
26 int jump_over_variable_init(bool b) {
27 if (b)
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000028 goto foo; // expected-warning {{goto into protected scope}}
Francois Pichet8b3c99e2011-09-18 21:48:27 +000029 C c; // expected-note {{jump bypasses variable initialization}}
30 foo:
31 return 1;
32 }
33
34struct Y {
35 ~Y();
36};
37
38void jump_over_var_with_dtor() {
39 goto end; // expected-warning{{goto into protected scope}}
Richard Smith0e9e9812011-10-20 21:42:12 +000040 Y y; // expected-note {{jump bypasses variable with a non-trivial destructor}}
Francois Pichet8b3c99e2011-09-18 21:48:27 +000041 end:
42 ;
43}
44
45 void jump_over_variable_case(int c) {
46 switch (c) {
47 case 0:
48 int x = 56; // expected-note {{jump bypasses variable initialization}}
49 case 1: // expected-error {{switch case is in protected scope}}
50 x = 10;
51 }
52 }
53
54
55void exception_jump() {
Richard Trieu2fe9b7f2011-12-15 00:38:15 +000056 goto l2; // expected-error {{goto into protected scope}}
Francois Pichet8b3c99e2011-09-18 21:48:27 +000057 try { // expected-note {{jump bypasses initialization of try block}}
58 l2: ;
59 } catch(int) {
60 }
61}
62
63int jump_over_indirect_goto() {
64 static void *ps[] = { &&a0 };
65 goto *&&a0; // expected-warning {{goto into protected scope}}
66 int a = 3; // expected-note {{jump bypasses variable initialization}}
67 a0:
68 return 0;
69}
70
71}
72
Nico Weber28976602012-01-23 04:01:33 +000073namespace PR11826 {
74 struct pair {
75 pair(int v) { }
76 void operator=(pair&& rhs) { }
77 };
78 void f() {
79 pair p0(3);
80 pair p = p0;
81 }
82}
Francois Pichet8b3c99e2011-09-18 21:48:27 +000083
Nico Weber28976602012-01-23 04:01:33 +000084namespace PR11826_for_symmetry {
85 struct pair {
86 pair(int v) { }
87 pair(pair&& rhs) { }
88 };
89 void f() {
90 pair p0(3);
91 pair p(4);
92 p = p0;
93 }
94}
Francois Pichet8b3c99e2011-09-18 21:48:27 +000095
Nico Weberc14ec5a2012-01-23 04:08:13 +000096namespace ms_using_declaration_bug {
97
98class A {
99public:
100 int f();
101};
102
103class B : public A {
104private:
105 using A::f;
106};
107
108class C : public B {
109private:
110 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}}
111};
112
113}
114
115
116namespace MissingTypename {
117
118template<class T> class A {
119public:
120 typedef int TYPE;
121};
122
123template<class T> class B {
124public:
125 typedef int TYPE;
126};
127
128
129template<class T, class U>
130class C : private A<T>, public B<U> {
131public:
132 typedef A<T> Base1;
133 typedef B<U> Base2;
134 typedef A<U> Base3;
135
136 A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
137 Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
138
139 B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
140 Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
141
142 A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
143 Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
144 };
145
146class D {
147public:
148 typedef int Type;
149};
150
151template <class T>
152void function_missing_typename(const T::Type param)// expected-warning {{missing 'typename' prior to dependent type name}}
153{
154 const T::Type var = 2; // expected-warning {{missing 'typename' prior to dependent type name}}
155}
156
157template void function_missing_typename<D>(const D::Type param);
158
159}
160
Francois Pichet6b6fb4f2012-01-21 23:26:50 +0000161enum ENUM2 {
162 ENUM2_a = (enum ENUM2) 4,
163 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
164 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
165};
Nico Weberc14ec5a2012-01-23 04:08:13 +0000166
167
Nico Weberdf1be862012-01-23 05:50:57 +0000168namespace PR11791 {
169 template<class _Ty>
170 void del(_Ty *_Ptr) {
171 _Ptr->~_Ty(); // expected-warning {{pseudo-destructors on type void are a Microsoft extension}}
172 }
173
174 void f() {
175 int* a = 0;
176 del((void*)a); // expected-note {{in instantiation of function template specialization}}
177 }
178}