xref: /minix3/external/bsd/llvm/dist/clang/test/SemaCXX/MicrosoftExtensions.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1f4a2713aSLionel Sambuc // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions
2f4a2713aSLionel Sambuc 
3f4a2713aSLionel Sambuc 
4f4a2713aSLionel Sambuc // Microsoft doesn't validate exception specification.
5f4a2713aSLionel Sambuc namespace microsoft_exception_spec {
6f4a2713aSLionel Sambuc 
7f4a2713aSLionel Sambuc void foo(); // expected-note {{previous declaration}}
8f4a2713aSLionel Sambuc void foo() throw(); // expected-warning {{exception specification in declaration does not match previous declaration}}
9f4a2713aSLionel Sambuc 
10f4a2713aSLionel Sambuc void r6() throw(...); // expected-note {{previous declaration}}
11f4a2713aSLionel Sambuc void r6() throw(int); // expected-warning {{exception specification in declaration does not match previous declaration}}
12f4a2713aSLionel Sambuc 
13f4a2713aSLionel Sambuc struct Base {
14f4a2713aSLionel Sambuc   virtual void f2();
15f4a2713aSLionel Sambuc   virtual void f3() throw(...);
16f4a2713aSLionel Sambuc };
17f4a2713aSLionel Sambuc 
18f4a2713aSLionel Sambuc struct Derived : Base {
19f4a2713aSLionel Sambuc   virtual void f2() throw(...);
20f4a2713aSLionel Sambuc   virtual void f3();
21f4a2713aSLionel Sambuc };
22f4a2713aSLionel Sambuc 
23f4a2713aSLionel Sambuc class A {
24f4a2713aSLionel Sambuc   virtual ~A() throw();  // expected-note {{overridden virtual function is here}}
25f4a2713aSLionel Sambuc };
26f4a2713aSLionel Sambuc 
27f4a2713aSLionel Sambuc class B : public A {
28f4a2713aSLionel Sambuc   virtual ~B();  // expected-warning {{exception specification of overriding function is more lax than base version}}
29f4a2713aSLionel Sambuc };
30f4a2713aSLionel Sambuc 
31f4a2713aSLionel Sambuc }
32f4a2713aSLionel Sambuc 
33f4a2713aSLionel Sambuc // MSVC allows type definition in anonymous union and struct
34f4a2713aSLionel Sambuc struct A
35f4a2713aSLionel Sambuc {
36f4a2713aSLionel Sambuc   union
37f4a2713aSLionel Sambuc   {
38f4a2713aSLionel Sambuc     int a;
39f4a2713aSLionel Sambuc     struct B  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
40f4a2713aSLionel Sambuc     {
41f4a2713aSLionel Sambuc       int c;
42f4a2713aSLionel Sambuc     } d;
43f4a2713aSLionel Sambuc 
44f4a2713aSLionel Sambuc     union C   // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
45f4a2713aSLionel Sambuc     {
46f4a2713aSLionel Sambuc       int e;
47f4a2713aSLionel Sambuc       int ee;
48f4a2713aSLionel Sambuc     } f;
49f4a2713aSLionel Sambuc 
50f4a2713aSLionel Sambuc     typedef int D;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
51f4a2713aSLionel Sambuc     struct F;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
52f4a2713aSLionel Sambuc   };
53f4a2713aSLionel Sambuc 
54f4a2713aSLionel Sambuc   struct
55f4a2713aSLionel Sambuc   {
56f4a2713aSLionel Sambuc     int a2;
57f4a2713aSLionel Sambuc 
58f4a2713aSLionel Sambuc     struct B2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
59f4a2713aSLionel Sambuc     {
60f4a2713aSLionel Sambuc       int c2;
61f4a2713aSLionel Sambuc     } d2;
62f4a2713aSLionel Sambuc 
63f4a2713aSLionel Sambuc 	union C2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
64f4a2713aSLionel Sambuc     {
65f4a2713aSLionel Sambuc       int e2;
66f4a2713aSLionel Sambuc       int ee2;
67f4a2713aSLionel Sambuc     } f2;
68f4a2713aSLionel Sambuc 
69f4a2713aSLionel Sambuc     typedef int D2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
70f4a2713aSLionel Sambuc     struct F2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
71f4a2713aSLionel Sambuc   };
72f4a2713aSLionel Sambuc };
73f4a2713aSLionel Sambuc 
74f4a2713aSLionel Sambuc // __stdcall handling
75f4a2713aSLionel Sambuc struct M {
76f4a2713aSLionel Sambuc     int __stdcall addP();
77f4a2713aSLionel Sambuc     float __stdcall subtractP();
78f4a2713aSLionel Sambuc };
79f4a2713aSLionel Sambuc 
80f4a2713aSLionel Sambuc // __unaligned handling
81f4a2713aSLionel Sambuc typedef char __unaligned *aligned_type;
82*0a6a1f1dSLionel Sambuc typedef struct UnalignedTag { int f; } __unaligned *aligned_type2;
83f4a2713aSLionel Sambuc 
84f4a2713aSLionel Sambuc 
h1(T (__stdcall M::* const)())85f4a2713aSLionel Sambuc template<typename T> void h1(T (__stdcall M::* const )()) { }
86f4a2713aSLionel Sambuc 
m1()87f4a2713aSLionel Sambuc void m1() {
88f4a2713aSLionel Sambuc   h1<int>(&M::addP);
89f4a2713aSLionel Sambuc   h1(&M::subtractP);
90f4a2713aSLionel Sambuc }
91f4a2713aSLionel Sambuc 
92f4a2713aSLionel Sambuc 
93f4a2713aSLionel Sambuc 
94f4a2713aSLionel Sambuc 
95f4a2713aSLionel Sambuc 
96f4a2713aSLionel Sambuc void f(long long);
97f4a2713aSLionel Sambuc void f(int);
98f4a2713aSLionel Sambuc 
main()99f4a2713aSLionel Sambuc int main()
100f4a2713aSLionel Sambuc {
101f4a2713aSLionel Sambuc   // This is an ambiguous call in standard C++.
102f4a2713aSLionel Sambuc   // This calls f(long long) in Microsoft mode because LL is always signed.
103f4a2713aSLionel Sambuc   f(0xffffffffffffffffLL);
104f4a2713aSLionel Sambuc   f(0xffffffffffffffffi64);
105f4a2713aSLionel Sambuc }
106f4a2713aSLionel Sambuc 
107f4a2713aSLionel Sambuc // Enumeration types with a fixed underlying type.
108f4a2713aSLionel Sambuc const int seventeen = 17;
109f4a2713aSLionel Sambuc typedef int Int;
110f4a2713aSLionel Sambuc 
111f4a2713aSLionel Sambuc struct X0 {
112f4a2713aSLionel Sambuc   enum E1 : Int { SomeOtherValue } field; // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}}
113f4a2713aSLionel Sambuc   enum E1 : seventeen;
114f4a2713aSLionel Sambuc };
115f4a2713aSLionel Sambuc 
116f4a2713aSLionel Sambuc enum : long long {  // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}}
117f4a2713aSLionel Sambuc   SomeValue = 0x100000000
118f4a2713aSLionel Sambuc };
119f4a2713aSLionel Sambuc 
120f4a2713aSLionel Sambuc 
121f4a2713aSLionel Sambuc class AAA {
f(void)122f4a2713aSLionel Sambuc __declspec(dllimport) void f(void) { }
123*0a6a1f1dSLionel Sambuc void f2(void); // expected-note{{previous declaration is here}}
124f4a2713aSLionel Sambuc };
125f4a2713aSLionel Sambuc 
f2(void)126*0a6a1f1dSLionel Sambuc __declspec(dllimport) void AAA::f2(void) { // expected-error{{dllimport cannot be applied to non-inline function definition}}
127*0a6a1f1dSLionel Sambuc                                            // expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}}
128f4a2713aSLionel Sambuc 
129f4a2713aSLionel Sambuc }
130f4a2713aSLionel Sambuc 
131f4a2713aSLionel Sambuc 
132f4a2713aSLionel Sambuc 
133f4a2713aSLionel Sambuc template <class T>
134f4a2713aSLionel Sambuc class BB {
135f4a2713aSLionel Sambuc public:
136f4a2713aSLionel Sambuc    void f(int g = 10 ); // expected-note {{previous definition is here}}
137f4a2713aSLionel Sambuc };
138f4a2713aSLionel Sambuc 
139f4a2713aSLionel Sambuc template <class T>
f(int g=0)140f4a2713aSLionel Sambuc void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
141f4a2713aSLionel Sambuc 
142f4a2713aSLionel Sambuc 
143f4a2713aSLionel Sambuc 
144f4a2713aSLionel Sambuc extern void static_func();
145f4a2713aSLionel Sambuc void static_func(); // expected-note {{previous declaration is here}}
146f4a2713aSLionel Sambuc 
147f4a2713aSLionel Sambuc 
static_func()148*0a6a1f1dSLionel Sambuc static void static_func() // expected-warning {{redeclaring non-static 'static_func' as static is a Microsoft extension}}
149f4a2713aSLionel Sambuc {
150f4a2713aSLionel Sambuc 
151f4a2713aSLionel Sambuc }
152f4a2713aSLionel Sambuc 
153*0a6a1f1dSLionel Sambuc extern const int static_var; // expected-note {{previous declaration is here}}
154*0a6a1f1dSLionel Sambuc static const int static_var = 3; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}}
155*0a6a1f1dSLionel Sambuc 
156f4a2713aSLionel Sambuc long function_prototype(int a);
157f4a2713aSLionel Sambuc long (*function_ptr)(int a);
158f4a2713aSLionel Sambuc 
function_to_voidptr_conv()159f4a2713aSLionel Sambuc void function_to_voidptr_conv() {
160f4a2713aSLionel Sambuc    void *a1 = function_prototype;
161f4a2713aSLionel Sambuc    void *a2 = &function_prototype;
162f4a2713aSLionel Sambuc    void *a3 = function_ptr;
163f4a2713aSLionel Sambuc }
164f4a2713aSLionel Sambuc 
165f4a2713aSLionel Sambuc 
pointer_to_integral_type_conv(char * ptr)166f4a2713aSLionel Sambuc void pointer_to_integral_type_conv(char* ptr) {
167f4a2713aSLionel Sambuc    char ch = (char)ptr;
168f4a2713aSLionel Sambuc    short sh = (short)ptr;
169f4a2713aSLionel Sambuc    ch = (char)ptr;
170f4a2713aSLionel Sambuc    sh = (short)ptr;
171f4a2713aSLionel Sambuc 
172f4a2713aSLionel Sambuc    // These are valid C++.
173f4a2713aSLionel Sambuc    bool b = (bool)ptr;
174f4a2713aSLionel Sambuc    b = static_cast<bool>(ptr);
175f4a2713aSLionel Sambuc 
176f4a2713aSLionel Sambuc    // This is bad.
177f4a2713aSLionel Sambuc    b = reinterpret_cast<bool>(ptr); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
178f4a2713aSLionel Sambuc }
179f4a2713aSLionel Sambuc 
180f4a2713aSLionel Sambuc struct PR11150 {
181f4a2713aSLionel Sambuc   class X {
182f4a2713aSLionel Sambuc     virtual void f() = 0;
183f4a2713aSLionel Sambuc   };
184f4a2713aSLionel Sambuc 
185f4a2713aSLionel Sambuc   int array[__is_abstract(X)? 1 : -1];
186f4a2713aSLionel Sambuc };
187f4a2713aSLionel Sambuc 
f()188f4a2713aSLionel Sambuc void f() { int __except = 0; }
189f4a2713aSLionel Sambuc 
190f4a2713aSLionel Sambuc void ::f(); // expected-warning{{extra qualification on member 'f'}}
191f4a2713aSLionel Sambuc 
192f4a2713aSLionel Sambuc class C {
193f4a2713aSLionel Sambuc   C::C(); // expected-warning{{extra qualification on member 'C'}}
194f4a2713aSLionel Sambuc };
195f4a2713aSLionel Sambuc 
196f4a2713aSLionel Sambuc struct StructWithProperty {
197f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) int V1;
198f4a2713aSLionel Sambuc   __declspec(property(put=SetV)) int V2;
199f4a2713aSLionel Sambuc   __declspec(property(get=GetV, put=SetV_NotExist)) int V3;
200f4a2713aSLionel Sambuc   __declspec(property(get=GetV_NotExist, put=SetV)) int V4;
201f4a2713aSLionel Sambuc   __declspec(property(get=GetV, put=SetV)) int V5;
202f4a2713aSLionel Sambuc 
GetVStructWithProperty203f4a2713aSLionel Sambuc   int GetV() { return 123; }
SetVStructWithProperty204f4a2713aSLionel Sambuc   void SetV(int i) {}
205f4a2713aSLionel Sambuc };
TestProperty()206f4a2713aSLionel Sambuc void TestProperty() {
207f4a2713aSLionel Sambuc   StructWithProperty sp;
208f4a2713aSLionel Sambuc   int i = sp.V2; // expected-error{{no getter defined for property 'V2'}}
209f4a2713aSLionel Sambuc   sp.V1 = 12; // expected-error{{no setter defined for property 'V1'}}
210f4a2713aSLionel Sambuc   int j = sp.V4; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}}
211f4a2713aSLionel Sambuc   sp.V3 = 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}}
212f4a2713aSLionel Sambuc   int k = sp.V5;
213f4a2713aSLionel Sambuc   sp.V5 = k++;
214f4a2713aSLionel Sambuc }
215f4a2713aSLionel Sambuc 
216f4a2713aSLionel Sambuc /* 4 tests for PseudoObject, begin */
217f4a2713aSLionel Sambuc struct SP1
218f4a2713aSLionel Sambuc {
operator ()SP1219f4a2713aSLionel Sambuc   bool operator()() { return true; }
220f4a2713aSLionel Sambuc };
221f4a2713aSLionel Sambuc struct SP2
222f4a2713aSLionel Sambuc {
223f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) SP1 V;
GetVSP2224f4a2713aSLionel Sambuc   SP1 GetV() { return SP1(); }
225f4a2713aSLionel Sambuc };
TestSP2()226f4a2713aSLionel Sambuc void TestSP2() {
227f4a2713aSLionel Sambuc   SP2 sp2;
228f4a2713aSLionel Sambuc   bool b = sp2.V();
229f4a2713aSLionel Sambuc }
230f4a2713aSLionel Sambuc 
231f4a2713aSLionel Sambuc struct SP3 {
232f4a2713aSLionel Sambuc   template <class T>
fSP3233f4a2713aSLionel Sambuc   void f(T t) {}
234f4a2713aSLionel Sambuc };
235f4a2713aSLionel Sambuc template <class T>
236f4a2713aSLionel Sambuc struct SP4
237f4a2713aSLionel Sambuc {
238f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) int V;
GetVSP4239f4a2713aSLionel Sambuc   int GetV() { return 123; }
fSP4240f4a2713aSLionel Sambuc   void f() { SP3 s2; s2.f(V); }
241f4a2713aSLionel Sambuc };
TestSP4()242f4a2713aSLionel Sambuc void TestSP4() {
243f4a2713aSLionel Sambuc   SP4<int> s;
244f4a2713aSLionel Sambuc   s.f();
245f4a2713aSLionel Sambuc }
246f4a2713aSLionel Sambuc 
247f4a2713aSLionel Sambuc template <class T>
248f4a2713aSLionel Sambuc struct SP5
249f4a2713aSLionel Sambuc {
250f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) T V;
GetVSP5251f4a2713aSLionel Sambuc   int GetV() { return 123; }
fSP5252f4a2713aSLionel Sambuc   void f() { int *p = new int[V]; }
253f4a2713aSLionel Sambuc };
254f4a2713aSLionel Sambuc 
255f4a2713aSLionel Sambuc template <class T>
256f4a2713aSLionel Sambuc struct SP6
257f4a2713aSLionel Sambuc {
258f4a2713aSLionel Sambuc public:
259f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) T V;
GetVSP6260f4a2713aSLionel Sambuc   T GetV() { return 123; }
fSP6261f4a2713aSLionel Sambuc   void f() { int t = V; }
262f4a2713aSLionel Sambuc };
TestSP6()263f4a2713aSLionel Sambuc void TestSP6() {
264f4a2713aSLionel Sambuc   SP6<int> c;
265f4a2713aSLionel Sambuc   c.f();
266f4a2713aSLionel Sambuc }
267f4a2713aSLionel Sambuc /* 4 tests for PseudoObject, end */
268f4a2713aSLionel Sambuc 
269f4a2713aSLionel Sambuc // Property access: explicit, implicit, with Qualifier
270f4a2713aSLionel Sambuc struct SP7 {
271f4a2713aSLionel Sambuc   __declspec(property(get=GetV, put=SetV)) int V;
GetVSP7272f4a2713aSLionel Sambuc   int GetV() { return 123; }
SetVSP7273f4a2713aSLionel Sambuc   void SetV(int v) {}
274f4a2713aSLionel Sambuc 
ImplicitAccessSP7275f4a2713aSLionel Sambuc   void ImplicitAccess() { int i = V; V = i; }
ExplicitAccessSP7276f4a2713aSLionel Sambuc   void ExplicitAccess() { int i = this->V; this->V = i; }
277f4a2713aSLionel Sambuc };
278f4a2713aSLionel Sambuc struct SP8: public SP7 {
AccessWithQualifierSP8279f4a2713aSLionel Sambuc   void AccessWithQualifier() { int i = SP7::V; SP7::V = i; }
280f4a2713aSLionel Sambuc };
281f4a2713aSLionel Sambuc 
282f4a2713aSLionel Sambuc // Property usage
283f4a2713aSLionel Sambuc template <class T>
284f4a2713aSLionel Sambuc struct SP9 {
285f4a2713aSLionel Sambuc   __declspec(property(get=GetV, put=SetV)) T V;
GetVSP9286f4a2713aSLionel Sambuc   T GetV() { return 0; }
SetVSP9287f4a2713aSLionel Sambuc   void SetV(T v) {}
fSP9288*0a6a1f1dSLionel Sambuc   bool f() { V = this->V; return V < this->V; }
gSP9289f4a2713aSLionel Sambuc   void g() { V++; }
hSP9290f4a2713aSLionel Sambuc   void h() { V*=2; }
291f4a2713aSLionel Sambuc };
292f4a2713aSLionel Sambuc struct SP10 {
SP10SP10293f4a2713aSLionel Sambuc   SP10(int v) {}
operator <SP10294f4a2713aSLionel Sambuc   bool operator<(const SP10& v) { return true; }
operator *SP10295f4a2713aSLionel Sambuc   SP10 operator*(int v) { return *this; }
operator +SP10296f4a2713aSLionel Sambuc   SP10 operator+(int v) { return *this; }
operator =SP10297f4a2713aSLionel Sambuc   SP10& operator=(const SP10& v) { return *this; }
298f4a2713aSLionel Sambuc };
TestSP9()299f4a2713aSLionel Sambuc void TestSP9() {
300f4a2713aSLionel Sambuc   SP9<int> c;
301f4a2713aSLionel Sambuc   int i = c.V; // Decl initializer
302f4a2713aSLionel Sambuc   i = c.V; // Binary op operand
303f4a2713aSLionel Sambuc   c.SetV(c.V); // CallExpr arg
304f4a2713aSLionel Sambuc   int *p = new int[c.V + 1]; // Array size
305f4a2713aSLionel Sambuc   p[c.V] = 1; // Array index
306f4a2713aSLionel Sambuc 
307f4a2713aSLionel Sambuc   c.V = 123; // Setter
308f4a2713aSLionel Sambuc 
309f4a2713aSLionel Sambuc   c.V++; // Unary op operand
310f4a2713aSLionel Sambuc   c.V *= 2; // Unary op operand
311f4a2713aSLionel Sambuc 
312f4a2713aSLionel Sambuc   SP9<int*> c2;
313f4a2713aSLionel Sambuc   c2.V[0] = 123; // Array
314f4a2713aSLionel Sambuc 
315f4a2713aSLionel Sambuc   SP9<SP10> c3;
316f4a2713aSLionel Sambuc   c3.f(); // Overloaded binary op operand
317f4a2713aSLionel Sambuc   c3.g(); // Overloaded incdec op operand
318f4a2713aSLionel Sambuc   c3.h(); // Overloaded unary op operand
319f4a2713aSLionel Sambuc }
320f4a2713aSLionel Sambuc 
321f4a2713aSLionel Sambuc union u {
322f4a2713aSLionel Sambuc   int *i1;
323f4a2713aSLionel Sambuc   int &i2;  // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
324f4a2713aSLionel Sambuc };
325f4a2713aSLionel Sambuc 
326f4a2713aSLionel Sambuc // Property getter using reference.
327f4a2713aSLionel Sambuc struct SP11 {
328f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) int V;
329f4a2713aSLionel Sambuc   int _v;
GetVSP11330f4a2713aSLionel Sambuc   int& GetV() { return _v; }
331f4a2713aSLionel Sambuc   void UseV();
TakePtrSP11332f4a2713aSLionel Sambuc   void TakePtr(int *) {}
TakeRefSP11333f4a2713aSLionel Sambuc   void TakeRef(int &) {}
TakeValSP11334f4a2713aSLionel Sambuc   void TakeVal(int) {}
335f4a2713aSLionel Sambuc };
336f4a2713aSLionel Sambuc 
UseV()337f4a2713aSLionel Sambuc void SP11::UseV() {
338f4a2713aSLionel Sambuc   TakePtr(&V);
339f4a2713aSLionel Sambuc   TakeRef(V);
340f4a2713aSLionel Sambuc   TakeVal(V);
341f4a2713aSLionel Sambuc }
342f4a2713aSLionel Sambuc 
343f4a2713aSLionel Sambuc struct StructWithUnnamedMember {
344f4a2713aSLionel Sambuc   __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}}
345f4a2713aSLionel Sambuc };
346f4a2713aSLionel Sambuc 
347f4a2713aSLionel Sambuc namespace rdar14250378 {
348f4a2713aSLionel Sambuc   class Bar {};
349f4a2713aSLionel Sambuc 
350f4a2713aSLionel Sambuc   namespace NyNamespace {
351f4a2713aSLionel Sambuc     class Foo {
352f4a2713aSLionel Sambuc     public:
353f4a2713aSLionel Sambuc       Bar* EnsureBar();
354f4a2713aSLionel Sambuc     };
355f4a2713aSLionel Sambuc 
356f4a2713aSLionel Sambuc     class Baz : public Foo {
357f4a2713aSLionel Sambuc     public:
358f4a2713aSLionel Sambuc       friend class Bar;
359f4a2713aSLionel Sambuc     };
360f4a2713aSLionel Sambuc 
EnsureBar()361f4a2713aSLionel Sambuc     Bar* Foo::EnsureBar() {
362f4a2713aSLionel Sambuc       return 0;
363f4a2713aSLionel Sambuc     }
364f4a2713aSLionel Sambuc   }
365f4a2713aSLionel Sambuc }
366f4a2713aSLionel Sambuc 
367f4a2713aSLionel Sambuc // expected-error@+1 {{'sealed' keyword not permitted with interface types}}
368f4a2713aSLionel Sambuc __interface InterfaceWithSealed sealed {
369f4a2713aSLionel Sambuc };
370f4a2713aSLionel Sambuc 
371f4a2713aSLionel Sambuc struct SomeBase {
372f4a2713aSLionel Sambuc   virtual void OverrideMe();
373f4a2713aSLionel Sambuc 
374f4a2713aSLionel Sambuc   // expected-note@+2 {{overridden virtual function is here}}
375f4a2713aSLionel Sambuc   // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
376*0a6a1f1dSLionel Sambuc   virtual void SealedFunction() sealed; // expected-note {{overridden virtual function is here}}
377f4a2713aSLionel Sambuc };
378f4a2713aSLionel Sambuc 
379f4a2713aSLionel Sambuc // expected-note@+2 {{'SealedType' declared here}}
380f4a2713aSLionel Sambuc // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
381f4a2713aSLionel Sambuc struct SealedType sealed : SomeBase {
382*0a6a1f1dSLionel Sambuc   // expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}}
383*0a6a1f1dSLionel Sambuc   // FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function.
384*0a6a1f1dSLionel Sambuc   virtual void SealedFunction(); // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}}
385f4a2713aSLionel Sambuc 
386f4a2713aSLionel Sambuc   // expected-warning@+1 {{'override' keyword is a C++11 extension}}
387f4a2713aSLionel Sambuc   virtual void OverrideMe() override;
388f4a2713aSLionel Sambuc };
389f4a2713aSLionel Sambuc 
390f4a2713aSLionel Sambuc // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
391f4a2713aSLionel Sambuc struct InheritFromSealed : SealedType {};
392*0a6a1f1dSLionel Sambuc 
AfterClassBody()393*0a6a1f1dSLionel Sambuc void AfterClassBody() {
394*0a6a1f1dSLionel Sambuc   // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
395*0a6a1f1dSLionel Sambuc   struct D {} __declspec(deprecated);
396*0a6a1f1dSLionel Sambuc 
397*0a6a1f1dSLionel Sambuc   struct __declspec(align(4)) S {} __declspec(align(8)) s1;
398*0a6a1f1dSLionel Sambuc   S s2;
399*0a6a1f1dSLionel Sambuc   _Static_assert(__alignof(S) == 4, "");
400*0a6a1f1dSLionel Sambuc   _Static_assert(__alignof(s1) == 8, "");
401*0a6a1f1dSLionel Sambuc   _Static_assert(__alignof(s2) == 4, "");
402*0a6a1f1dSLionel Sambuc }
403