blob: 6a12d0dc963f08e99f9803f5902b33d560e59463 [file] [log] [blame]
John McCall018591f2011-03-02 02:04:40 +00001// RUN: %clang_cc1 %s -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
Douglas Gregor5b6f7692010-08-30 15:04:51 +00007// The following three are all equivalent when ms-extensions are on
8void foo() throw(int);
9void foo() throw(int, long);
10void foo() throw(...);
11void foo(); // expected-note {{previous declaration}}
Douglas Gregor5c0ca522010-08-30 14:44:26 +000012
Douglas Gregor5b6f7692010-08-30 15:04:51 +000013// Only nothrow specification is treated specially.
14void foo() throw(); // expected-error {{exception specification in declaration does not match previous declaration}}
15
16// throw(...)
17void r3();
18void r3() throw(...);
19
20void r6() throw(...);
21void r6() throw(int); // okay
22
23struct Base {
24 virtual void f2();
25 virtual void f3() throw(...);
26};
27
28struct Derived : Base {
29 virtual void f2() throw(...);
30 virtual void f3();
31};
Douglas Gregorafac01d2010-09-01 16:29:03 +000032
Francois Pichet538e0d02010-09-08 11:32:25 +000033
34// MSVC allows type definition in anonymous union and struct
35struct A
36{
37 union
38 {
39 int a;
40 struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
41 {
42 int c;
43 } d;
44
45 union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
46 {
47 int e;
48 int ee;
49 } f;
50
51 typedef int D; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
52 struct F; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
53 };
54
55 struct
56 {
57 int a2;
58
59 struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
60 {
61 int c2;
62 } d2;
63
64 union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
65 {
66 int e2;
67 int ee2;
68 } f2;
69
70 typedef int D2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
71 struct F2; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
72 };
73};
74
Douglas Gregorafac01d2010-09-01 16:29:03 +000075// __stdcall handling
76struct M {
77 int __stdcall addP();
78 float __stdcall subtractP();
79};
80
81template<typename T> void h1(T (__stdcall M::* const )()) { }
82
83void m1() {
84 h1<int>(&M::addP);
85 h1(&M::subtractP);
86}
Francois Pichet8dc3abc2010-09-12 05:06:55 +000087
88//MSVC allows forward enum declaration
89enum ENUM; // expected-warning {{forward references to 'enum' types are a Microsoft extension}}
Francois Pichet842e7a22010-10-18 15:01:13 +000090ENUM *var = 0;
91ENUM var2 = (ENUM)3;
92enum ENUM1* var3 = 0;// expected-warning {{forward references to 'enum' types are a Microsoft extension}}
93
94
95enum ENUM2 {
96 ENUM2_a = (enum ENUM2) 4,
97 ENUM2_b = 0x9FFFFFFF, // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
98 ENUM2_c = 0x100000000 // expected-warning {{enumerator value is not representable in the underlying type 'int'}}
99};
Francois Pichet5be38be2011-01-17 01:08:01 +0000100
101
102void f(long long);
103void f(int);
104
105int main()
106{
107 // This is an ambiguous call in standard C++.
108 // This calls f(long long) in Microsoft mode because LL is always signed.
109 f(0xffffffffffffffffLL);
110 f(0xffffffffffffffffi64);
111}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000112
113// Enumeration types with a fixed underlying type.
114const int seventeen = 17;
115typedef int Int;
116
117struct X0 {
118 enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
119 enum E1 : seventeen;
120};
121
Douglas Gregor1756ce42011-02-22 21:42:31 +0000122enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a Microsoft extension}}
Douglas Gregor86f208c2011-02-22 20:32:04 +0000123 SomeValue = 0x100000000
124};