blob: 22a06673b951689d8bc99caf6ba59e57e65581b8 [file] [log] [blame]
Francois Pichetdde385d2011-03-29 11:38:04 +00001// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify -fms-extensions -fexceptions -fcxx-exceptions
Douglas Gregor5c0ca522010-08-30 14:44:26 +00002
3
4// ::type_info is predeclared with forward class declartion
5void f(const type_info &a);
6
Francois Picheteedd4672011-03-19 23:05:18 +00007
8// Microsoft doesn't validate exception specification.
Francois Pichet0f161592011-05-24 02:11:43 +00009namespace microsoft_exception_spec {
10
Douglas Gregor5b6f7692010-08-30 15:04:51 +000011void foo(); // expected-note {{previous declaration}}
Francois Picheteedd4672011-03-19 23:05:18 +000012void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
Douglas Gregor5c0ca522010-08-30 14:44:26 +000013
Francois Picheteedd4672011-03-19 23:05:18 +000014void r6() throw(...); // expected-note {{previous declaration}}
15void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
Douglas Gregor5b6f7692010-08-30 15:04:51 +000016
17struct Base {
18 virtual void f2();
19 virtual void f3() throw(...);
20};
21
22struct Derived : Base {
23 virtual void f2() throw(...);
24 virtual void f3();
25};
Douglas Gregorafac01d2010-09-01 16:29:03 +000026
Francois Pichet0f161592011-05-24 02:11:43 +000027class A {
28 virtual ~A() throw(); // expected-note {{overridden virtual function is here}}
29};
30
31class B : public A {
32 virtual ~B(); // expected-warning {{exception specification of overriding function is more lax than base version}}
33};
34
35}
Francois Pichet538e0d02010-09-08 11:32:25 +000036
37// MSVC allows type definition in anonymous union and struct
38struct A
39{
40 union
41 {
42 int a;
43 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
44 {
45 int c;
46 } d;
47
48 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
49 {
50 int e;
51 int ee;
52 } f;
53
54 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
55 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
56 };
57
58 struct
59 {
60 int a2;
61
62 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
63 {
64 int c2;
65 } d2;
66
67 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
68 {
69 int e2;
70 int ee2;
71 } f2;
72
73 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
74 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
75 };
76};
77
Douglas Gregorafac01d2010-09-01 16:29:03 +000078// __stdcall handling
79struct M {
80 int __stdcall addP();
81 float __stdcall subtractP();
82};
83
84template<typename T> void h1(T (__stdcall M::* const )()) { }
85
86void m1() {
87 h1<int>(&M::addP);
88 h1(&M::subtractP);
89}
Francois Pichet8dc3abc2010-09-12 05:06:55 +000090
91//MSVC allows forward enum declaration
92enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
Francois Pichet842e7a22010-10-18 15:01:13 +000093ENUM *var = 0;
94ENUM var2 = (ENUM)3;
95enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
96
97
98enum ENUM2 {
99 ENUM2_a = (enum ENUM2) 4,
100 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
101 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
102};
Francois Pichet5be38be2011-01-17 01:08:01 +0000103
104
105void f(long long);
106void f(int);
107
108int main()
109{
110 // This is an ambiguous call in standard C++.
111 // This calls f(long long) in Microsoft mode because LL is always signed.
112 f(0xffffffffffffffffLL);
113 f(0xffffffffffffffffi64);
114}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000115
116// Enumeration types with a fixed underlying type.
117const int seventeen = 17;
118typedef int Int;
119
120struct X0 {
121 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
122 enum E1 : seventeen;
123};
124
Douglas Gregor1756ce42011-02-22 21:42:31 +0000125enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000126 SomeValue = 0x100000000
127};
Francois Pichetb613cd62011-03-29 10:39:17 +0000128
129
130class AAA {
131__declspec(dllimport) void f(void) { }
132void f2(void);
133};
134
135__declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}}
136
137}
138
139
140
Francois Pichet8d051e02011-04-10 03:03:52 +0000141template <class T>
142class BB {
143public:
144 void f(int g = 10 ); // expected-note {{previous definition is here}}
145};
146
147template <class T>
148void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
149
Francois Pichet6943e9b2011-04-13 02:38:49 +0000150
151namespace MissingTypename {
152
153template<class T> class A {
154public:
155 typedef int TYPE;
156};
157
158template<class T> class B {
159public:
160 typedef int TYPE;
161};
162
163
164template<class T, class U>
165class C : private A<T>, public B<U> {
166public:
167 typedef A<T> Base1;
168 typedef B<U> Base2;
169 typedef A<U> Base3;
170
171 A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
172 Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
173
174 B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
175 Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
176
177 A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
178 Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
179 };
180
Francois Pichet2e510a02011-04-22 08:14:00 +0000181}
182
183
184
185
186extern void static_func();
187void static_func(); // expected-note {{previous declaration is here}}
188
189
190static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}}
191{
192
Francois Picheta8ef3ac2011-05-08 22:52:41 +0000193}
194
195long function_prototype(int a);
196long (*function_ptr)(int a);
197
198void function_to_voidptr_conv() {
199 void *a1 = function_prototype;
200 void *a2 = &function_prototype;
Francois Pichetb594fac2011-05-08 23:15:10 +0000201 void *a3 = function_ptr;
Francois Picheta8ef3ac2011-05-08 22:52:41 +0000202}
Francois Pichet30aff5b2011-05-11 22:13:54 +0000203
204
205void pointer_to_integral_type_conv(char* ptr) {
206 char ch = (char)ptr;
207 short sh = (short)ptr;
208 ch = (char)ptr;
209 sh = (short)ptr;
210}
Francois Pichetb2ee8302011-05-23 03:43:44 +0000211
212namespace ms_using_declaration_bug {
213
214class A {
215public:
216 int f();
217};
218
219class B : public A {
220private:
221 using A::f;
222};
223
224class C : public B {
225private:
226 using B::f; // expected-warning {{using declaration refers to inaccessible member 'ms_using_declaration_bug::B::f', which refers to accessible member 'ms_using_declaration_bug::A::f', accepted for Microsoft compatibility}}
227};
228
229}