blob: 0b72cd3e1fc0db73d90adcdd8b4eb3b18940f0c5 [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
Francois Pichet3bd9aa42011-08-18 09:59:55 +000084// __unaligned handling
85typedef char __unaligned *aligned_type;
86
87
Douglas Gregorafac01d2010-09-01 16:29:03 +000088template<typename T> void h1(T (__stdcall M::* const )()) { }
89
90void m1() {
91 h1<int>(&M::addP);
92 h1(&M::subtractP);
93}
Francois Pichet8dc3abc2010-09-12 05:06:55 +000094
Francois Pichet842e7a22010-10-18 15:01:13 +000095
96
Francois Pichet5be38be2011-01-17 01:08:01 +000097
98
99void f(long long);
100void f(int);
101
102int main()
103{
104 // This is an ambiguous call in standard C++.
105 // This calls f(long long) in Microsoft mode because LL is always signed.
106 f(0xffffffffffffffffLL);
107 f(0xffffffffffffffffi64);
108}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000109
110// Enumeration types with a fixed underlying type.
111const int seventeen = 17;
112typedef int Int;
113
114struct X0 {
115 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
116 enum E1 : seventeen;
117};
118
Douglas Gregor1756ce42011-02-22 21:42:31 +0000119enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000120 SomeValue = 0x100000000
121};
Francois Pichetb613cd62011-03-29 10:39:17 +0000122
123
124class AAA {
125__declspec(dllimport) void f(void) { }
126void f2(void);
127};
128
129__declspec(dllimport) void AAA::f2(void) { // expected-error {{dllimport attribute can be applied only to symbol}}
130
131}
132
133
134
Francois Pichet8d051e02011-04-10 03:03:52 +0000135template <class T>
136class BB {
137public:
138 void f(int g = 10 ); // expected-note {{previous definition is here}}
139};
140
141template <class T>
142void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
143
Francois Pichet6943e9b2011-04-13 02:38:49 +0000144
Francois Pichet2e510a02011-04-22 08:14:00 +0000145
146extern void static_func();
147void static_func(); // expected-note {{previous declaration is here}}
148
149
150static void static_func() // expected-warning {{static declaration of 'static_func' follows non-static declaration}}
151{
152
Francois Picheta8ef3ac2011-05-08 22:52:41 +0000153}
154
155long function_prototype(int a);
156long (*function_ptr)(int a);
157
158void function_to_voidptr_conv() {
159 void *a1 = function_prototype;
160 void *a2 = &function_prototype;
Francois Pichetb594fac2011-05-08 23:15:10 +0000161 void *a3 = function_ptr;
Francois Picheta8ef3ac2011-05-08 22:52:41 +0000162}
Francois Pichet30aff5b2011-05-11 22:13:54 +0000163
164
165void pointer_to_integral_type_conv(char* ptr) {
166 char ch = (char)ptr;
167 short sh = (short)ptr;
168 ch = (char)ptr;
169 sh = (short)ptr;
170}
Francois Pichetb2ee8302011-05-23 03:43:44 +0000171
Francois Pichetb4746032011-06-01 04:14:20 +0000172
173namespace friend_as_a_forward_decl {
174
175class A {
176 class Nested {
177 friend class B;
178 B* b;
179 };
180 B* b;
181};
182B* global_b;
183
184
185void f()
186{
187 class Local {
188 friend class Z;
189 Z* b;
190 };
191 Z* b;
192}
193
Francois Pichetc985b882011-09-13 10:26:51 +0000194}
195
Douglas Gregora2b4e5d2011-10-17 17:09:53 +0000196struct PR11150 {
197 class X {
198 virtual void f() = 0;
199 };
200
201 int array[__is_abstract(X)? 1 : -1];
202};
Douglas Gregorb57791e2011-10-21 03:57:52 +0000203
204void f() { int __except = 0; }
205