blob: 40492608c04d58f11634c478a407edb93222f747 [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.
Douglas Gregor5b6f7692010-08-30 15:04:51 +00009void foo(); // expected-note {{previous declaration}}
Francois Picheteedd4672011-03-19 23:05:18 +000010void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
Douglas Gregor5c0ca522010-08-30 14:44:26 +000011
Francois Picheteedd4672011-03-19 23:05:18 +000012void r6() throw(...); // expected-note {{previous declaration}}
13void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
Douglas Gregor5b6f7692010-08-30 15:04:51 +000014
15struct Base {
16 virtual void f2();
17 virtual void f3() throw(...);
18};
19
20struct Derived : Base {
21 virtual void f2() throw(...);
22 virtual void f3();
23};
Douglas Gregorafac01d2010-09-01 16:29:03 +000024
Francois Pichet538e0d02010-09-08 11:32:25 +000025
26// MSVC allows type definition in anonymous union and struct
27struct A
28{
29 union
30 {
31 int a;
32 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
33 {
34 int c;
35 } d;
36
37 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
38 {
39 int e;
40 int ee;
41 } f;
42
43 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
44 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
45 };
46
47 struct
48 {
49 int a2;
50
51 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
52 {
53 int c2;
54 } d2;
55
56 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
57 {
58 int e2;
59 int ee2;
60 } f2;
61
62 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
63 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
64 };
65};
66
Douglas Gregorafac01d2010-09-01 16:29:03 +000067// __stdcall handling
68struct M {
69 int __stdcall addP();
70 float __stdcall subtractP();
71};
72
73template<typename T> void h1(T (__stdcall M::* const )()) { }
74
75void m1() {
76 h1<int>(&M::addP);
77 h1(&M::subtractP);
78}
Francois Pichet8dc3abc2010-09-12 05:06:55 +000079
80//MSVC allows forward enum declaration
81enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
Francois Pichet842e7a22010-10-18 15:01:13 +000082ENUM *var = 0;
83ENUM var2 = (ENUM)3;
84enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
85
86
87enum ENUM2 {
88 ENUM2_a = (enum ENUM2) 4,
89 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
90 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
91};
Francois Pichet5be38be2011-01-17 01:08:01 +000092
93
94void f(long long);
95void f(int);
96
97int main()
98{
99 // This is an ambiguous call in standard C++.
100 // This calls f(long long) in Microsoft mode because LL is always signed.
101 f(0xffffffffffffffffLL);
102 f(0xffffffffffffffffi64);
103}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000104
105// Enumeration types with a fixed underlying type.
106const int seventeen = 17;
107typedef int Int;
108
109struct X0 {
110 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
111 enum E1 : seventeen;
112};
113
Douglas Gregor1756ce42011-02-22 21:42:31 +0000114enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000115 SomeValue = 0x100000000
116};
Francois Pichetb613cd62011-03-29 10:39:17 +0000117
118
119class AAA {
120__declspec(dllimport) void f(void) { }
121void f2(void);
122};
123
124__declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}}
125
126}
127
128
129
Francois Pichet8d051e02011-04-10 03:03:52 +0000130template <class T>
131class BB {
132public:
133 void f(int g = 10 ); // expected-note {{previous definition is here}}
134};
135
136template <class T>
137void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
138
Francois Pichet6943e9b2011-04-13 02:38:49 +0000139
140namespace MissingTypename {
141
142template<class T> class A {
143public:
144 typedef int TYPE;
145};
146
147template<class T> class B {
148public:
149 typedef int TYPE;
150};
151
152
153template<class T, class U>
154class C : private A<T>, public B<U> {
155public:
156 typedef A<T> Base1;
157 typedef B<U> Base2;
158 typedef A<U> Base3;
159
160 A<T>::TYPE a1; // expected-warning {{missing 'typename' prior to dependent type name}}
161 Base1::TYPE a2; // expected-warning {{missing 'typename' prior to dependent type name}}
162
163 B<U>::TYPE a3; // expected-warning {{missing 'typename' prior to dependent type name}}
164 Base2::TYPE a4; // expected-warning {{missing 'typename' prior to dependent type name}}
165
166 A<U>::TYPE a5; // expected-error {{missing 'typename' prior to dependent type name}}
167 Base3::TYPE a6; // expected-error {{missing 'typename' prior to dependent type name}}
168 };
169
Francois Pichet2e510a02011-04-22 08:14:00 +0000170}
171
172
173
174
175extern void static_func();
176void static_func(); // expected-note {{previous declaration is here}}
177
178
179static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}}
180{
181
Francois Picheta8ef3ac2011-05-08 22:52:41 +0000182}
183
184long function_prototype(int a);
185long (*function_ptr)(int a);
186
187void function_to_voidptr_conv() {
188 void *a1 = function_prototype;
189 void *a2 = &function_prototype;
190 void *a1 = function_ptr;
191 void *a2 = &function_ptr;
192}