1 // RUN: %clang_cc1 -std=c++17 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -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 -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 -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 -fexceptions -fcxx-exceptions -DTEST2
5 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -std=c++11 -fms-compatibility -verify -DTEST3
9 // MSVC allows type definition in anonymous union and struct
15 struct B
// expected-warning {{types declared in an anonymous union are a Microsoft extension}}
20 union C
// expected-warning {{types declared in an anonymous union are a Microsoft extension}}
26 typedef int D
; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
27 struct F
; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
34 struct B2
// expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
39 union C2
// expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
45 typedef int D2
; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
46 struct F2
; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
53 float __stdcall
subtractP();
56 // __unaligned handling
57 typedef char __unaligned
*aligned_type
;
58 typedef struct UnalignedTag
{ int f
; } __unaligned
*aligned_type2
;
59 typedef char __unaligned aligned_type3
;
61 struct aligned_type4
{
65 __unaligned
int aligned_type4::*p1_aligned_type4
= &aligned_type4::i
;
66 int aligned_type4::* __unaligned p2_aligned_type4
= &aligned_type4::i
;
67 __unaligned
int aligned_type4::* __unaligned p3_aligned_type4
= &aligned_type4::i
;
68 void (aligned_type4::*__unaligned p4_aligned_type4
)();
70 // Check that __unaligned qualifier can be used for overloading
71 void foo_unaligned(int *arg
) {} // expected-note {{not viable: 1st argument ('const __unaligned int *') would lose const qualifier}}
72 void foo_unaligned(__unaligned
int *arg
) {} // expected-note {{not viable: 1st argument ('const __unaligned int *') would lose const qualifier}}
73 void foo_unaligned(int arg
) {} // expected-note {{previous definition is here}}
74 void foo_unaligned(__unaligned
int arg
) {} // expected-error {{redefinition of 'foo_unaligned'}} \
75 // expected-note {{not viable: no known conversion from 'const __unaligned int *' to '__unaligned int'}}
77 class B_unaligned
: public A_unaligned
{};
78 int foo_unaligned(__unaligned A_unaligned
*arg
) { return 0; } // expected-note {{not viable: no known conversion from 'const __unaligned int *' to '__unaligned A_unaligned *'}}
79 void *foo_unaligned(B_unaligned
*arg
) { return 0; } // expected-note {{not viable: no known conversion from 'const __unaligned int *' to 'B_unaligned *'}}
81 void test_unaligned() {
85 const __unaligned
int *const_p1
= 0;
86 foo_unaligned(const_p1
); // expected-error {{no matching function for call to 'foo_unaligned'}}
88 __unaligned
int *p2
= 0;
91 __unaligned B_unaligned
*p3
= 0;
92 int p4
= foo_unaligned(p3
); // expected-error {{cannot initialize a variable of type 'int' with an rvalue of type 'void *'}}
93 // expected-warning@-1 {{implicit cast from type '__unaligned B_unaligned *' to type 'B_unaligned *' drops __unaligned qualifier}}
96 // expected-warning@-1 {{implicit cast from type '__unaligned B_unaligned *' to type 'B_unaligned *' drops __unaligned qualifier}}
98 __unaligned B_unaligned
*p6
= p3
;
100 p1_aligned_type4
= p2_aligned_type4
;
101 p2_aligned_type4
= p1_aligned_type4
;
102 // expected-warning@-1 {{implicit cast from type '__unaligned int aligned_type4::*' to type 'int aligned_type4::*' drops __unaligned qualifier}}
103 p3_aligned_type4
= p1_aligned_type4
;
105 __unaligned
int a
[10];
107 // expected-warning@-1 {{implicit cast from type '__unaligned int[10]' to type 'int *' drops __unaligned qualifier}}
111 // We should accept assignment of an __unaligned pointer to a non-__unaligned
113 typedef struct _ITEMIDLIST
{ int i
; } ITEMIDLIST
;
114 typedef ITEMIDLIST __unaligned
*LPITEMIDLIST
;
115 extern "C" __declspec(dllimport
) void __stdcall
CoTaskMemFree(void* pv
);
116 __inline
void FreeIDListArray(LPITEMIDLIST
*ppidls
) {
117 CoTaskMemFree(*ppidls
);
118 __unaligned
int *x
= 0;
123 // We should accept type conversion of __unaligned to non-__unaligned references
124 typedef struct in_addr
{
126 in_addr(in_addr
&a
) {} // precxx17-note {{candidate constructor not viable: expects an lvalue for 1st argument}}
127 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 void f(IN_ADDR __unaligned
*a
) {
131 IN_ADDR local_addr
= *a
;
132 // FIXME: MSVC accepts the following; not sure why clang tries to
133 // copy-construct an in_addr.
134 IN_ADDR local_addr2
= a
; // precxx17-error {{no viable constructor copying variable of type 'IN_ADDR' (aka 'in_addr')}}
135 // expected-warning@-1 {{implicit cast from type '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to type 'in_addr *' drops __unaligned qualifier}}
136 IN_ADDR
local_addr3(a
);
137 // expected-warning@-1 {{implicit cast from type '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to type 'in_addr *' drops __unaligned qualifier}}
140 template<typename T
> void h1(T (__stdcall
M::* const )()) { }
148 namespace signed_hex_i64
{
149 void f(long long); // expected-note {{candidate function}}
150 void f(int); // expected-note {{candidate function}}
152 // This used to be controlled by -fms-extensions, but it is now under
153 // -fms-compatibility.
154 f(0xffffffffffffffffLL
); // expected-error {{call to 'f' is ambiguous}}
155 f(0xffffffffffffffffi
64);
159 // Enumeration types with a fixed underlying type.
160 const int seventeen
= 17;
164 enum E1
: Int
{ SomeOtherValue
} field
;
165 #if __cplusplus <= 199711L
166 // expected-warning@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
170 #if __cplusplus >= 201103L
171 // expected-error@-2 {{bit-field}}
175 #if __cplusplus <= 199711L
176 // expected-warning@+2 {{enumeration types with a fixed underlying type are a C++11 extension}}
179 SomeValue
= 0x100000000
184 __declspec(dllimport
) void f(void) { }
185 void f2(void); // expected-note{{previous declaration is here}}
188 __declspec(dllimport
) void AAA::f2(void) { // expected-error{{dllimport cannot be applied to non-inline function definition}}
189 // expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}}
198 void f(int g
= 10 ); // expected-note {{previous definition is here}}
202 void BB
<T
>::f(int g
= 0) { } // expected-warning {{redefinition of default argument}}
206 extern void static_func();
207 void static_func(); // expected-note {{previous declaration is here}}
210 static void static_func() // expected-warning {{redeclaring non-static 'static_func' as static is a Microsoft extension}}
215 extern const int static_var
; // expected-note {{previous declaration is here}}
216 static const int static_var
= 3; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}}
218 void pointer_to_integral_type_conv(char* ptr
) {
219 char ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'char *'}}
220 short sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'char *'}}
221 ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'char *'}}
222 sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'char *'}}
224 // These are valid C++.
226 b
= static_cast<bool>(ptr
);
229 b
= reinterpret_cast<bool>(ptr
); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
232 void void_pointer_to_integral_type_conv(void *ptr
) {
233 char ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'void *'}}
234 short sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'void *'}}
235 ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'void *'}}
236 sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'void *'}}
238 // These are valid C++.
240 b
= static_cast<bool>(ptr
);
243 b
= reinterpret_cast<bool>(ptr
); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
248 virtual void f() = 0;
251 int array
[__is_abstract(X
)? 1 : -1];
254 void f() { int __except
= 0; }
256 void ::f(); // expected-warning{{extra qualification on member 'f'}}
259 C::C(); // expected-warning{{extra qualification on member 'C'}}
262 struct StructWithProperty
{
263 __declspec(property(get
=GetV
)) int V1
;
264 __declspec(property(put
=SetV
)) int V2
;
265 __declspec(property(get
=GetV
, put
=SetV_NotExist
)) int V3
;
266 __declspec(property(get
=GetV_NotExist
, put
=SetV
)) int V4
;
267 __declspec(property(get
=GetV
, put
=SetV
)) int V5
;
269 int GetV() { return 123; }
272 void TestProperty() {
273 StructWithProperty sp
;
274 int i
= sp
.V2
; // expected-error{{no getter defined for property 'V2'}}
275 sp
.V1
= 12; // expected-error{{no setter defined for property 'V1'}}
276 int j
= sp
.V4
; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}}
277 sp
.V3
= 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}}
282 /* 4 tests for PseudoObject, begin */
285 bool operator()() { return true; }
289 __declspec(property(get
=GetV
)) SP1 V
;
290 SP1
GetV() { return SP1(); }
304 __declspec(property(get
=GetV
)) int V
;
305 int GetV() { return 123; }
306 void f() { SP3 s2
; s2
.f(V
); }
316 __declspec(property(get
=GetV
)) T V
;
317 int GetV() { return 123; }
318 void f() { int *p
= new int[V
]; }
325 __declspec(property(get
=GetV
)) T V
;
326 T
GetV() { return 123; }
327 void f() { int t
= V
; }
333 /* 4 tests for PseudoObject, end */
335 // Property access: explicit, implicit, with Qualifier
337 __declspec(property(get
=GetV
, put
=SetV
)) int V
;
338 int GetV() { return 123; }
341 void ImplicitAccess() { int i
= V
; V
= i
; }
342 void ExplicitAccess() { int i
= this->V
; this->V
= i
; }
344 struct SP8
: public SP7
{
345 void AccessWithQualifier() { int i
= SP7::V
; SP7::V
= i
; }
351 __declspec(property(get
=GetV
, put
=SetV
)) T V
;
352 T
GetV() { return 0; }
354 bool f() { V
= this->V
; return V
< this->V
; }
360 bool operator<(const SP10
& v
) { return true; }
361 SP10
operator*(int v
) { return *this; }
362 SP10
operator+(int v
) { return *this; }
363 SP10
& operator=(const SP10
& v
) { return *this; }
367 int i
= c
.V
; // Decl initializer
368 i
= c
.V
; // Binary op operand
369 c
.SetV(c
.V
); // CallExpr arg
370 int *p
= new int[c
.V
+ 1]; // Array size
371 p
[c
.V
] = 1; // Array index
375 c
.V
++; // Unary op operand
376 c
.V
*= 2; // Unary op operand
379 c2
.V
[0] = 123; // Array
382 c3
.f(); // Overloaded binary op operand
383 c3
.g(); // Overloaded incdec op operand
384 c3
.h(); // Overloaded unary op operand
389 int &i2
; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
392 // Property getter using reference.
394 __declspec(property(get
=GetV
)) int V
;
396 int& GetV() { return _v
; }
398 void TakePtr(int *) {}
399 void TakeRef(int &) {}
409 struct StructWithUnnamedMember
{
410 __declspec(property(get
=GetV
)) int : 10; // expected-error {{anonymous property is not supported}}
413 struct MSPropertyClass
{
414 int get() { return 42; }
415 int __declspec(property(get
= get
)) n
;
418 int *f(MSPropertyClass
&x
) {
419 return &x
.n
; // expected-error {{address of property expression requested}}
421 int MSPropertyClass::*g() {
422 return &MSPropertyClass::n
; // expected-error {{address of property expression requested}}
425 namespace rdar14250378
{
428 namespace NyNamespace
{
434 class Baz
: public Foo
{
439 Bar
* Foo::EnsureBar() {
445 // expected-error@+1 {{'sealed' keyword not permitted with interface types}}
446 __interface InterfaceWithSealed sealed
{
450 virtual void OverrideMe();
452 // expected-note@+2 {{overridden virtual function is here}}
453 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
454 virtual void SealedFunction() sealed
; // expected-note {{overridden virtual function is here}}
457 // expected-note@+2 {{'SealedType' declared here}}
458 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
459 struct SealedType sealed
: SomeBase
{
460 // expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}}
461 // FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function.
462 virtual void SealedFunction(); // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}}
464 #if __cplusplus <= 199711L
465 // expected-warning@+2 {{'override' keyword is a C++11 extension}}
467 virtual void OverrideMe() override
;
470 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
471 struct InheritFromSealed
: SealedType
{};
473 class SealedDestructor
{ // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}}
474 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
475 virtual ~SealedDestructor() sealed
; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}}
478 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
479 class AbstractClass abstract
{
483 // expected-error@+1 {{variable type 'AbstractClass' is an abstract class}}
484 AbstractClass abstractInstance
;
486 // expected-warning@+4 {{abstract class is marked 'sealed'}}
487 // expected-note@+3 {{'AbstractAndSealedClass' declared here}}
488 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
489 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
490 class AbstractAndSealedClass abstract sealed
{}; // Does no really make sense, but allowed
492 // expected-error@+1 {{variable type 'AbstractAndSealedClass' is an abstract class}}
493 AbstractAndSealedClass abstractAndSealedInstance
;
494 // expected-error@+1 {{base 'AbstractAndSealedClass' is marked 'sealed'}}
495 class InheritFromAbstractAndSealed
: AbstractAndSealedClass
{};
497 #if __cplusplus <= 199711L
498 // expected-warning@+4 {{'final' keyword is a C++11 extension}}
499 // expected-warning@+3 {{'final' keyword is a C++11 extension}}
501 // expected-error@+1 {{class already marked 'final'}}
502 class TooManyVirtSpecifiers1 final final
{};
503 #if __cplusplus <= 199711L
504 // expected-warning@+4 {{'final' keyword is a C++11 extension}}
506 // expected-warning@+2 {{'sealed' keyword is a Microsoft extension}}
507 // expected-error@+1 {{class already marked 'sealed'}}
508 class TooManyVirtSpecifiers2 final sealed
{};
509 #if __cplusplus <= 199711L
510 // expected-warning@+6 {{'final' keyword is a C++11 extension}}
511 // expected-warning@+5 {{'final' keyword is a C++11 extension}}
513 // expected-warning@+3 {{abstract class is marked 'final'}}
514 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
515 // expected-error@+1 {{class already marked 'final'}}
516 class TooManyVirtSpecifiers3 final abstract final
{};
517 #if __cplusplus <= 199711L
518 // expected-warning@+6 {{'final' keyword is a C++11 extension}}
520 // expected-warning@+4 {{abstract class is marked 'final'}}
521 // expected-warning@+3 {{'abstract' keyword is a Microsoft extension}}
522 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
523 // expected-error@+1 {{class already marked 'abstract'}}
524 class TooManyVirtSpecifiers4 abstract final abstract
{};
529 class AbstractFunctionInClass
: public Base
{
530 // expected-note@+2 {{unimplemented pure virtual method 'f' in 'AbstractFunctionInClass'}}
531 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
532 virtual void f() abstract
;
533 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
534 void g() abstract
; // expected-error {{'g' is not virtual and cannot be declared pure}}
535 // expected-note@+2 {{unimplemented pure virtual method 'h' in 'AbstractFunctionInClass'}}
536 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
537 virtual void h() abstract
= 0; // expected-error {{class member already marked 'abstract'}}
538 #if __cplusplus <= 199711L
539 // expected-warning@+4 {{'override' keyword is a C++11 extension}}
541 // expected-note@+2 {{unimplemented pure virtual method 'i' in 'AbstractFunctionInClass'}}
542 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
543 virtual void i() abstract override
;
546 // expected-error@+1 {{variable type 'AbstractFunctionInClass' is an abstract class}}
547 AbstractFunctionInClass abstractFunctionInClassInstance
;
549 void AfterClassBody() {
550 // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
551 struct D
{} __declspec(deprecated
);
553 struct __declspec(align(4)) S
{} __declspec(align(8)) s1
;
555 _Static_assert(__alignof(S
) == 4, "");
556 _Static_assert(__alignof(s1
) == 8, "");
557 _Static_assert(__alignof(s2
) == 4, "");
561 template <typename TX
> struct A
{
562 template <bool> struct largest_type_select
;
563 template <> struct largest_type_select
<false> {
564 blah x
; // expected-error {{unknown type name 'blah'}}
569 class PR34109_class
{
571 virtual ~PR34109_class() {}
574 void operator delete(void *) throw();
575 // expected-note@-1 {{previous declaration is here}}
576 __declspec(dllexport
) void operator delete(void *) throw();
577 // expected-error@-1 {{redeclaration of 'operator delete' cannot add 'dllexport' attribute}}
579 void PR34109(int* a
) {
585 __attribute__((nothrow
)) void Foo(); // expected-note {{previous declaration is here}}
586 __attribute__((nothrow
)) void Bar();
588 void S::Foo(){} // expected-warning {{is missing exception specification}}
589 __attribute__((nothrow
)) void S::Bar(){}
592 namespace UnalignedConv
{
594 bool operator==(int) const;
606 // Check that __unaligned is not recognized if MS extensions are not enabled
607 typedef char __unaligned
*aligned_type
; // expected-error {{expected ';' after top level declarator}}
612 template<typename T
> struct A
{};
613 template<typename T
> struct B
: A
<A
<T
>> { A
<T
>::C::D d
; }; // expected-warning {{implicit 'typename' is a C++20 extension}}
618 #error Unknown test mode