xref: /llvm-project/clang/test/SemaCXX/MicrosoftExtensions.cpp (revision 9088ac1e8335d32bed275fbd33f0cd1b9bd400d6)
1 // RUN: %clang_cc1 -std=c++17 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify=expected,ms-union-ext -fms-extensions -fexceptions -fcxx-exceptions -DTEST1
2 // RUN: %clang_cc1 -std=c++98 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify=expected,precxx17,ms-union-ext -fms-extensions -fexceptions -fcxx-exceptions -DTEST1
3 // RUN: %clang_cc1 -std=c++11 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify=expected,precxx17,ms-union-ext -fms-extensions -fexceptions -fcxx-exceptions -DTEST1
4 // RUN: %clang_cc1 -std=c++14 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify=expected,precxx17,ms-union-ext-disabled -fexceptions -fcxx-exceptions -DTEST2
5 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -fms-compatibility -verify=expected,ms-union-ext -DTEST3
6 // RUN: %clang_cc1 -std=c++17 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify=ms-union-ext -fms-extensions -fms-compatibility-version=18.00
7 // RUN: %clang_cc1 -std=c++17 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -verify=ms-union-ext-disabled -fms-extensions -fms-compatibility-version=19.00
8 
9 #if TEST1
10 
11 // MSVC allows type definition in anonymous union and struct
12 struct A
13 {
14   union
15   {
16     int a;
17     struct B  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
18     {
19       int c;
20     } d;
21 
22     union C   // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
23     {
24       int e;
25       int ee;
26     } f;
27 
28     typedef int D;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
29     struct F;  // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
30   };
31 
32   struct
33   {
34     int a2;
35 
36     struct B2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
37     {
38       int c2;
39     } d2;
40 
41 	union C2  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
42     {
43       int e2;
44       int ee2;
45     } f2;
46 
47     typedef int D2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
48     struct F2;  // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
49   };
50 };
51 
52 // __stdcall handling
53 struct M {
54     int __stdcall addP();
55     float __stdcall subtractP();
56 };
57 
58 // __unaligned handling
59 typedef char __unaligned *aligned_type;
60 typedef struct UnalignedTag { int f; } __unaligned *aligned_type2;
61 typedef char __unaligned aligned_type3;
62 
63 struct aligned_type4 {
64   int i;
65 };
66 
67 __unaligned int aligned_type4::*p1_aligned_type4 = &aligned_type4::i;
68 int aligned_type4::* __unaligned p2_aligned_type4 = &aligned_type4::i;
69 __unaligned int aligned_type4::* __unaligned p3_aligned_type4 = &aligned_type4::i;
70 void (aligned_type4::*__unaligned p4_aligned_type4)();
71 
72 // Check that __unaligned qualifier can be used for overloading
73 void foo_unaligned(int *arg) {} // expected-note {{not viable: 1st argument ('const __unaligned int *') would lose const qualifier}}
74 void foo_unaligned(__unaligned int *arg) {} // expected-note {{not viable: 1st argument ('const __unaligned int *') would lose const qualifier}}
75 void foo_unaligned(int arg) {} // expected-note {{previous definition is here}}
76 void foo_unaligned(__unaligned int arg) {} // expected-error {{redefinition of 'foo_unaligned'}} \
77                                            // expected-note {{not viable: no known conversion from 'const __unaligned int *' to '__unaligned int'}}
78 class A_unaligned {};
79 class B_unaligned : public A_unaligned {};
80 int foo_unaligned(__unaligned A_unaligned *arg) { return 0; } // expected-note {{not viable: no known conversion from 'const __unaligned int *' to '__unaligned A_unaligned *'}}
81 void *foo_unaligned(B_unaligned *arg) { return 0; } // expected-note {{not viable: no known conversion from 'const __unaligned int *' to 'B_unaligned *'}}
82 
83 void test_unaligned() {
84   int *p1 = 0;
85   foo_unaligned(p1);
86 
87   const __unaligned int *const_p1 = 0;
88   foo_unaligned(const_p1); // expected-error {{no matching function for call to 'foo_unaligned'}}
89 
90   __unaligned int *p2 = 0;
91   foo_unaligned(p2);
92 
93   __unaligned B_unaligned *p3 = 0;
94   int p4 = foo_unaligned(p3); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
95   // expected-warning@-1 {{implicit cast from type '__unaligned B_unaligned *' to type 'B_unaligned *' drops __unaligned qualifier}}
96 
97   B_unaligned *p5 = p3;
98   // expected-warning@-1 {{implicit cast from type '__unaligned B_unaligned *' to type 'B_unaligned *' drops __unaligned qualifier}}
99 
100   __unaligned B_unaligned *p6 = p3;
101 
102   p1_aligned_type4 = p2_aligned_type4;
103   p2_aligned_type4 = p1_aligned_type4;
104   // expected-warning@-1 {{implicit cast from type '__unaligned int aligned_type4::*' to type 'int aligned_type4::*' drops __unaligned qualifier}}
105   p3_aligned_type4 = p1_aligned_type4;
106 
107   __unaligned int a[10];
108   int *b = a;
109   // expected-warning@-1 {{implicit cast from type '__unaligned int[10]' to type 'int *' drops __unaligned qualifier}}
110 }
111 
112 // Test from PR27367
113 // We should accept assignment of an __unaligned pointer to a non-__unaligned
114 // pointer to void
115 typedef struct _ITEMIDLIST { int i; } ITEMIDLIST;
116 typedef ITEMIDLIST __unaligned *LPITEMIDLIST;
117 extern "C" __declspec(dllimport) void __stdcall CoTaskMemFree(void* pv);
118 __inline void FreeIDListArray(LPITEMIDLIST *ppidls) {
119   CoTaskMemFree(*ppidls);
120   __unaligned int *x = 0;
121   void *y = x;
122 }
123 
124 // Test from PR27666
125 // We should accept type conversion of __unaligned to non-__unaligned references
126 typedef struct in_addr {
127 public:
128   in_addr(in_addr &a) {} // precxx17-note {{candidate constructor not viable: expects an lvalue for 1st argument}}
129   in_addr(in_addr *a) {} // precxx17-note {{candidate constructor not viable: no known conversion from 'IN_ADDR' (aka 'in_addr') to 'in_addr *' for 1st argument}}
130 } IN_ADDR;
131 
132 void f(IN_ADDR __unaligned *a) {
133   IN_ADDR local_addr = *a;
134   // FIXME: MSVC accepts the following; not sure why clang tries to
135   // copy-construct an in_addr.
136   IN_ADDR local_addr2 = a; // precxx17-error {{no viable constructor copying variable of type 'IN_ADDR' (aka 'in_addr')}}
137   // expected-warning@-1 {{implicit cast from type '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to type 'in_addr *' drops __unaligned qualifier}}
138   IN_ADDR local_addr3(a);
139   // expected-warning@-1 {{implicit cast from type '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to type 'in_addr *' drops __unaligned qualifier}}
140 }
141 
142 template<typename T> void h1(T (__stdcall M::* const )()) { }
143 
144 void m1() {
145   h1<int>(&M::addP);
146   h1(&M::subtractP);
147 }
148 
149 
150 namespace signed_hex_i64 {
151 void f(long long); // expected-note {{candidate function}}
152 void f(int); // expected-note {{candidate function}}
153 void g() {
154   // This used to be controlled by -fms-extensions, but it is now under
155   // -fms-compatibility.
156   f(0xffffffffffffffffLL); // expected-error {{call to 'f' is ambiguous}}
157   f(0xffffffffffffffffi64);
158 }
159 }
160 
161 // Enumeration types with a fixed underlying type.
162 const int seventeen = 17;
163 typedef int Int;
164 
165 struct X0 {
166   enum E1 : Int { SomeOtherValue } field;
167 #if __cplusplus <= 199711L
168   // expected-warning@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
169 #endif
170 
171   enum E1 : seventeen;
172 #if __cplusplus >= 201103L
173   // expected-error@-2 {{bit-field}}
174 #endif
175 };
176 
177 #if __cplusplus <= 199711L
178 // expected-warning@+2 {{enumeration types with a fixed underlying type are a C++11 extension}}
179 #endif
180 enum : long long {
181   SomeValue = 0x100000000
182 };
183 
184 
185 class AAA {
186 __declspec(dllimport) void f(void) { }
187 void f2(void); // expected-note{{previous declaration is here}}
188 };
189 
190 __declspec(dllimport) void AAA::f2(void) { // expected-error{{dllimport cannot be applied to non-inline function definition}}
191                                            // expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}}
192 
193 }
194 
195 
196 
197 template <class T>
198 class BB {
199 public:
200    void f(int g = 10 ); // expected-note {{previous definition is here}}
201 };
202 
203 template <class T>
204 void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
205 
206 
207 
208 extern void static_func();
209 void static_func(); // expected-note {{previous declaration is here}}
210 
211 
212 static void static_func() // expected-warning {{redeclaring non-static 'static_func' as static is a Microsoft extension}}
213 {
214 
215 }
216 
217 extern const int static_var; // expected-note {{previous declaration is here}}
218 static const int static_var = 3; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}}
219 
220 void pointer_to_integral_type_conv(char* ptr) {
221   char ch = (char)ptr;   // expected-warning {{cast to smaller integer type 'char' from 'char *'}}
222   short sh = (short)ptr; // expected-warning {{cast to smaller integer type 'short' from 'char *'}}
223   ch = (char)ptr;        // expected-warning {{cast to smaller integer type 'char' from 'char *'}}
224   sh = (short)ptr;       // expected-warning {{cast to smaller integer type 'short' from 'char *'}}
225 
226   // These are valid C++.
227   bool b = (bool)ptr;
228   b = static_cast<bool>(ptr);
229 
230   // This is bad.
231   b = reinterpret_cast<bool>(ptr); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
232 }
233 
234 void void_pointer_to_integral_type_conv(void *ptr) {
235   char ch = (char)ptr;   // expected-warning {{cast to smaller integer type 'char' from 'void *'}}
236   short sh = (short)ptr; // expected-warning {{cast to smaller integer type 'short' from 'void *'}}
237   ch = (char)ptr;        // expected-warning {{cast to smaller integer type 'char' from 'void *'}}
238   sh = (short)ptr;       // expected-warning {{cast to smaller integer type 'short' from 'void *'}}
239 
240   // These are valid C++.
241   bool b = (bool)ptr;
242   b = static_cast<bool>(ptr);
243 
244   // This is bad.
245   b = reinterpret_cast<bool>(ptr); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
246 }
247 
248 struct PR11150 {
249   class X {
250     virtual void f() = 0;
251   };
252 
253   int array[__is_abstract(X)? 1 : -1];
254 };
255 
256 void f() { int __except = 0; }
257 
258 void ::f(); // expected-warning{{extra qualification on member 'f'}}
259 
260 class C {
261   C::C(); // expected-warning{{extra qualification on member 'C'}}
262 };
263 
264 struct StructWithProperty {
265   __declspec(property(get=GetV)) int V1;
266   __declspec(property(put=SetV)) int V2;
267   __declspec(property(get=GetV, put=SetV_NotExist)) int V3;
268   __declspec(property(get=GetV_NotExist, put=SetV)) int V4;
269   __declspec(property(get=GetV, put=SetV)) int V5;
270 
271   int GetV() { return 123; }
272   void SetV(int i) {}
273 };
274 void TestProperty() {
275   StructWithProperty sp;
276   int i = sp.V2; // expected-error{{no getter defined for property 'V2'}}
277   sp.V1 = 12; // expected-error{{no setter defined for property 'V1'}}
278   int j = sp.V4; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}}
279   sp.V3 = 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}}
280   int k = sp.V5;
281   sp.V5 = k++;
282 }
283 
284 /* 4 tests for PseudoObject, begin */
285 struct SP1
286 {
287   bool operator()() { return true; }
288 };
289 struct SP2
290 {
291   __declspec(property(get=GetV)) SP1 V;
292   SP1 GetV() { return SP1(); }
293 };
294 void TestSP2() {
295   SP2 sp2;
296   bool b = sp2.V();
297 }
298 
299 struct SP3 {
300   template <class T>
301   void f(T t) {}
302 };
303 template <class T>
304 struct SP4
305 {
306   __declspec(property(get=GetV)) int V;
307   int GetV() { return 123; }
308   void f() { SP3 s2; s2.f(V); }
309 };
310 void TestSP4() {
311   SP4<int> s;
312   s.f();
313 }
314 
315 template <class T>
316 struct SP5
317 {
318   __declspec(property(get=GetV)) T V;
319   int GetV() { return 123; }
320   void f() { int *p = new int[V]; }
321 };
322 
323 template <class T>
324 struct SP6
325 {
326 public:
327   __declspec(property(get=GetV)) T V;
328   T GetV() { return 123; }
329   void f() { int t = V; }
330 };
331 void TestSP6() {
332   SP6<int> c;
333   c.f();
334 }
335 /* 4 tests for PseudoObject, end */
336 
337 // Property access: explicit, implicit, with Qualifier
338 struct SP7 {
339   __declspec(property(get=GetV, put=SetV)) int V;
340   int GetV() { return 123; }
341   void SetV(int v) {}
342 
343   void ImplicitAccess() { int i = V; V = i; }
344   void ExplicitAccess() { int i = this->V; this->V = i; }
345 };
346 struct SP8: public SP7 {
347   void AccessWithQualifier() { int i = SP7::V; SP7::V = i; }
348 };
349 
350 // Property usage
351 template <class T>
352 struct SP9 {
353   __declspec(property(get=GetV, put=SetV)) T V;
354   T GetV() { return 0; }
355   void SetV(T v) {}
356   bool f() { V = this->V; return V < this->V; }
357   void g() { V++; }
358   void h() { V*=2; }
359 };
360 struct SP10 {
361   SP10(int v) {}
362   bool operator<(const SP10& v) { return true; }
363   SP10 operator*(int v) { return *this; }
364   SP10 operator+(int v) { return *this; }
365   SP10& operator=(const SP10& v) { return *this; }
366 };
367 void TestSP9() {
368   SP9<int> c;
369   int i = c.V; // Decl initializer
370   i = c.V; // Binary op operand
371   c.SetV(c.V); // CallExpr arg
372   int *p = new int[c.V + 1]; // Array size
373   p[c.V] = 1; // Array index
374 
375   c.V = 123; // Setter
376 
377   c.V++; // Unary op operand
378   c.V *= 2; // Unary op operand
379 
380   SP9<int*> c2;
381   c2.V[0] = 123; // Array
382 
383   SP9<SP10> c3;
384   c3.f(); // Overloaded binary op operand
385   c3.g(); // Overloaded incdec op operand
386   c3.h(); // Overloaded unary op operand
387 }
388 
389 // Property getter using reference.
390 struct SP11 {
391   __declspec(property(get=GetV)) int V;
392   int _v;
393   int& GetV() { return _v; }
394   void UseV();
395   void TakePtr(int *) {}
396   void TakeRef(int &) {}
397   void TakeVal(int) {}
398 };
399 
400 void SP11::UseV() {
401   TakePtr(&V);
402   TakeRef(V);
403   TakeVal(V);
404 }
405 
406 struct StructWithUnnamedMember {
407   __declspec(property(get=GetV)) int : 10; // expected-error {{anonymous property is not supported}}
408 };
409 
410 struct MSPropertyClass {
411   int get() { return 42; }
412   int __declspec(property(get = get)) n;
413 };
414 
415 int *f(MSPropertyClass &x) {
416   return &x.n; // expected-error {{address of property expression requested}}
417 }
418 int MSPropertyClass::*g() {
419   return &MSPropertyClass::n; // expected-error {{address of property expression requested}}
420 }
421 
422 namespace rdar14250378 {
423   class Bar {};
424 
425   namespace NyNamespace {
426     class Foo {
427     public:
428       Bar* EnsureBar();
429     };
430 
431     class Baz : public Foo {
432     public:
433       friend class Bar;
434     };
435 
436     Bar* Foo::EnsureBar() {
437       return 0;
438     }
439   }
440 }
441 
442 // expected-error@+1 {{'sealed' keyword not permitted with interface types}}
443 __interface InterfaceWithSealed sealed {
444 };
445 
446 struct SomeBase {
447   virtual void OverrideMe();
448 
449   // expected-note@+2 {{overridden virtual function is here}}
450   // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
451   virtual void SealedFunction() sealed; // expected-note {{overridden virtual function is here}}
452 };
453 
454 // expected-note@+2 {{'SealedType' declared here}}
455 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
456 struct SealedType sealed : SomeBase {
457   // expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}}
458   // FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function.
459   virtual void SealedFunction(); // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}}
460 
461 #if __cplusplus <= 199711L
462   // expected-warning@+2 {{'override' keyword is a C++11 extension}}
463 #endif
464   virtual void OverrideMe() override;
465 };
466 
467 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
468 struct InheritFromSealed : SealedType {};
469 
470 class SealedDestructor { // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}}
471     // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
472     virtual ~SealedDestructor() sealed; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}}
473 };
474 
475 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
476 class AbstractClass abstract {
477   int i;
478 };
479 
480 // expected-error@+1 {{variable type 'AbstractClass' is an abstract class}}
481 AbstractClass abstractInstance;
482 
483 // expected-warning@+4 {{abstract class is marked 'sealed'}}
484 // expected-note@+3 {{'AbstractAndSealedClass' declared here}}
485 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
486 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
487 class AbstractAndSealedClass abstract sealed {}; // Does no really make sense, but allowed
488 
489 // expected-error@+1 {{variable type 'AbstractAndSealedClass' is an abstract class}}
490 AbstractAndSealedClass abstractAndSealedInstance;
491 // expected-error@+1 {{base 'AbstractAndSealedClass' is marked 'sealed'}}
492 class InheritFromAbstractAndSealed : AbstractAndSealedClass {};
493 
494 #if __cplusplus <= 199711L
495 // expected-warning@+4 {{'final' keyword is a C++11 extension}}
496 // expected-warning@+3 {{'final' keyword is a C++11 extension}}
497 #endif
498 // expected-error@+1 {{class already marked 'final'}}
499 class TooManyVirtSpecifiers1 final final {};
500 #if __cplusplus <= 199711L
501 // expected-warning@+4 {{'final' keyword is a C++11 extension}}
502 #endif
503 // expected-warning@+2 {{'sealed' keyword is a Microsoft extension}}
504 // expected-error@+1 {{class already marked 'sealed'}}
505 class TooManyVirtSpecifiers2 final sealed {};
506 #if __cplusplus <= 199711L
507 // expected-warning@+6 {{'final' keyword is a C++11 extension}}
508 // expected-warning@+5 {{'final' keyword is a C++11 extension}}
509 #endif
510 // expected-warning@+3 {{abstract class is marked 'final'}}
511 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
512 // expected-error@+1 {{class already marked 'final'}}
513 class TooManyVirtSpecifiers3 final abstract final {};
514 #if __cplusplus <= 199711L
515 // expected-warning@+6 {{'final' keyword is a C++11 extension}}
516 #endif
517 // expected-warning@+4 {{abstract class is marked 'final'}}
518 // expected-warning@+3 {{'abstract' keyword is a Microsoft extension}}
519 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
520 // expected-error@+1 {{class already marked 'abstract'}}
521 class TooManyVirtSpecifiers4 abstract final abstract {};
522 
523 class Base {
524   virtual void i();
525 };
526 class AbstractFunctionInClass : public Base {
527   // expected-note@+2 {{unimplemented pure virtual method 'f' in 'AbstractFunctionInClass'}}
528   // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
529   virtual void f() abstract;
530   // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
531   void g() abstract; // expected-error {{'g' is not virtual and cannot be declared pure}}
532   // expected-note@+2 {{unimplemented pure virtual method 'h' in 'AbstractFunctionInClass'}}
533   // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
534   virtual void h() abstract = 0; // expected-error {{class member already marked 'abstract'}}
535 #if __cplusplus <= 199711L
536   // expected-warning@+4 {{'override' keyword is a C++11 extension}}
537 #endif
538   // expected-note@+2 {{unimplemented pure virtual method 'i' in 'AbstractFunctionInClass'}}
539   // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
540   virtual void i() abstract override;
541 };
542 
543 // expected-error@+1 {{variable type 'AbstractFunctionInClass' is an abstract class}}
544 AbstractFunctionInClass abstractFunctionInClassInstance;
545 
546 void AfterClassBody() {
547   // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
548   struct D {} __declspec(deprecated);
549 
550   struct __declspec(align(4)) S {} __declspec(align(8)) s1;
551   S s2;
552   _Static_assert(__alignof(S) == 4, "");
553   _Static_assert(__alignof(s1) == 8, "");
554   _Static_assert(__alignof(s2) == 4, "");
555 }
556 
557 namespace PR24246 {
558 template <typename TX> struct A {
559   template <bool> struct largest_type_select;
560   template <> struct largest_type_select<false> {
561     blah x;  // expected-error {{unknown type name 'blah'}}
562   };
563 };
564 }
565 
566 class PR34109_class {
567   PR34109_class() {}
568   virtual ~PR34109_class() {}
569 };
570 
571 #if !defined(__cpp_sized_deallocation)
572 void operator delete(void *) throw();
573 // expected-note@-1 {{previous declaration is here}}
574 __declspec(dllexport) void operator delete(void *) throw();
575 // expected-error@-1  {{redeclaration of 'operator delete' cannot add 'dllexport' attribute}}
576 #else
577 void operator delete(void *, unsigned int) throw();
578 // expected-note@-1 {{previous declaration is here}}
579 __declspec(dllexport) void operator delete(void *, unsigned int) throw();
580 // expected-error@-1  {{redeclaration of 'operator delete' cannot add 'dllexport' attribute}}
581 #endif
582 void PR34109(int* a) {
583   delete a;
584 }
585 
586 namespace PR42089 {
587   struct S {
588     __attribute__((nothrow)) void Foo(); // expected-note {{previous declaration is here}}
589     __attribute__((nothrow)) void Bar();
590   };
591   void S::Foo(){} // expected-warning {{is missing exception specification}}
592   __attribute__((nothrow)) void S::Bar(){}
593 }
594 
595 namespace UnalignedConv {
596 struct S {
597   bool operator==(int) const;
598 };
599 
600 int func() {
601   S __unaligned s;
602   return s == 42;
603 }
604 }
605 
606 
607 #elif TEST2
608 
609 // Check that __unaligned is not recognized if MS extensions are not enabled
610 typedef char __unaligned *aligned_type; // expected-error {{expected ';' after top level declarator}}
611 
612 #elif TEST3
613 
614 namespace PR32750 {
615 template<typename T> struct A {};
616 template<typename T> struct B : A<A<T>> { A<T>::C::D d; }; // expected-warning {{implicit 'typename' is a C++20 extension}}
617 }
618 
619 #endif
620 
621 union u {
622     int *i1;
623 
624     // ms-union-ext-warning@+2 {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
625     // ms-union-ext-disabled-error@+1 {{union member 'i2' has reference type 'int &'}}
626     int &i2;
627 };
628