1 // RUN: %clang_cc1 %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 -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 -fms-extensions -fexceptions -fcxx-exceptions -DTEST1
4 // RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -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
) {}
72 void foo_unaligned(__unaligned
int *arg
) {}
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'}}
76 class B_unaligned
: public A_unaligned
{};
77 int foo_unaligned(__unaligned A_unaligned
*arg
) { return 0; }
78 void *foo_unaligned(B_unaligned
*arg
) { return 0; }
80 void test_unaligned() {
84 __unaligned
int *p2
= 0;
87 __unaligned B_unaligned
*p3
= 0;
88 int p4
= foo_unaligned(p3
);
90 B_unaligned
*p5
= p3
; // expected-error {{cannot initialize a variable of type 'B_unaligned *' with an lvalue of type '__unaligned B_unaligned *'}}
92 __unaligned B_unaligned
*p6
= p3
;
94 p1_aligned_type4
= p2_aligned_type4
;
95 p2_aligned_type4
= p1_aligned_type4
; // expected-error {{assigning to 'int aligned_type4::*' from incompatible type '__unaligned int aligned_type4::*'}}
96 p3_aligned_type4
= p1_aligned_type4
;
98 __unaligned
int a
[10];
99 int *b
= a
; // expected-error {{cannot initialize a variable of type 'int *' with an lvalue of type '__unaligned int[10]'}}
103 // We should accept assignment of an __unaligned pointer to a non-__unaligned
105 typedef struct _ITEMIDLIST
{ int i
; } ITEMIDLIST
;
106 typedef ITEMIDLIST __unaligned
*LPITEMIDLIST
;
107 extern "C" __declspec(dllimport
) void __stdcall
CoTaskMemFree(void* pv
);
108 __inline
void FreeIDListArray(LPITEMIDLIST
*ppidls
) {
109 CoTaskMemFree(*ppidls
);
110 __unaligned
int *x
= 0;
115 // We should accept type conversion of __unaligned to non-__unaligned references
116 typedef struct in_addr
{
118 in_addr(in_addr
&a
) {} // expected-note {{candidate constructor not viable: no known conversion from '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to 'in_addr &' for 1st argument; dereference the argument with *}}
119 in_addr(in_addr
*a
) {} // expected-note {{candidate constructor not viable: 1st argument ('__unaligned IN_ADDR *' (aka '__unaligned in_addr *')) would lose __unaligned qualifier}}
122 void f(IN_ADDR __unaligned
*a
) {
123 IN_ADDR local_addr
= *a
;
124 IN_ADDR local_addr2
= a
; // expected-error {{no viable conversion from '__unaligned IN_ADDR *' (aka '__unaligned in_addr *') to 'IN_ADDR' (aka 'in_addr')}}
127 template<typename T
> void h1(T (__stdcall
M::* const )()) { }
135 namespace signed_hex_i64
{
136 void f(long long); // expected-note {{candidate function}}
137 void f(int); // expected-note {{candidate function}}
139 // This used to be controlled by -fms-extensions, but it is now under
140 // -fms-compatibility.
141 f(0xffffffffffffffffLL
); // expected-error {{call to 'f' is ambiguous}}
142 f(0xffffffffffffffffi
64);
146 // Enumeration types with a fixed underlying type.
147 const int seventeen
= 17;
151 enum E1
: Int
{ SomeOtherValue
} field
;
152 #if __cplusplus <= 199711L
153 // expected-warning@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
157 #if __cplusplus >= 201103L
158 // expected-error@-2 {{bit-field}}
162 #if __cplusplus <= 199711L
163 // expected-warning@+2 {{enumeration types with a fixed underlying type are a C++11 extension}}
166 SomeValue
= 0x100000000
171 __declspec(dllimport
) void f(void) { }
172 void f2(void); // expected-note{{previous declaration is here}}
175 __declspec(dllimport
) void AAA::f2(void) { // expected-error{{dllimport cannot be applied to non-inline function definition}}
176 // expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}}
185 void f(int g
= 10 ); // expected-note {{previous definition is here}}
189 void BB
<T
>::f(int g
= 0) { } // expected-warning {{redefinition of default argument}}
193 extern void static_func();
194 void static_func(); // expected-note {{previous declaration is here}}
197 static void static_func() // expected-warning {{redeclaring non-static 'static_func' as static is a Microsoft extension}}
202 extern const int static_var
; // expected-note {{previous declaration is here}}
203 static const int static_var
= 3; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}}
205 void pointer_to_integral_type_conv(char* ptr
) {
206 char ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'char *'}}
207 short sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'char *'}}
208 ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'char *'}}
209 sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'char *'}}
211 // These are valid C++.
213 b
= static_cast<bool>(ptr
);
216 b
= reinterpret_cast<bool>(ptr
); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
219 void void_pointer_to_integral_type_conv(void *ptr
) {
220 char ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'void *'}}
221 short sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'void *'}}
222 ch
= (char)ptr
; // expected-warning {{cast to smaller integer type 'char' from 'void *'}}
223 sh
= (short)ptr
; // expected-warning {{cast to smaller integer type 'short' from 'void *'}}
225 // These are valid C++.
227 b
= static_cast<bool>(ptr
);
230 b
= reinterpret_cast<bool>(ptr
); // expected-error {{cast from pointer to smaller type 'bool' loses information}}
235 virtual void f() = 0;
238 int array
[__is_abstract(X
)? 1 : -1];
241 void f() { int __except
= 0; }
243 void ::f(); // expected-warning{{extra qualification on member 'f'}}
246 C::C(); // expected-warning{{extra qualification on member 'C'}}
249 struct StructWithProperty
{
250 __declspec(property(get
=GetV
)) int V1
;
251 __declspec(property(put
=SetV
)) int V2
;
252 __declspec(property(get
=GetV
, put
=SetV_NotExist
)) int V3
;
253 __declspec(property(get
=GetV_NotExist
, put
=SetV
)) int V4
;
254 __declspec(property(get
=GetV
, put
=SetV
)) int V5
;
256 int GetV() { return 123; }
259 void TestProperty() {
260 StructWithProperty sp
;
261 int i
= sp
.V2
; // expected-error{{no getter defined for property 'V2'}}
262 sp
.V1
= 12; // expected-error{{no setter defined for property 'V1'}}
263 int j
= sp
.V4
; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}}
264 sp
.V3
= 14; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}}
269 /* 4 tests for PseudoObject, begin */
272 bool operator()() { return true; }
276 __declspec(property(get
=GetV
)) SP1 V
;
277 SP1
GetV() { return SP1(); }
291 __declspec(property(get
=GetV
)) int V
;
292 int GetV() { return 123; }
293 void f() { SP3 s2
; s2
.f(V
); }
303 __declspec(property(get
=GetV
)) T V
;
304 int GetV() { return 123; }
305 void f() { int *p
= new int[V
]; }
312 __declspec(property(get
=GetV
)) T V
;
313 T
GetV() { return 123; }
314 void f() { int t
= V
; }
320 /* 4 tests for PseudoObject, end */
322 // Property access: explicit, implicit, with Qualifier
324 __declspec(property(get
=GetV
, put
=SetV
)) int V
;
325 int GetV() { return 123; }
328 void ImplicitAccess() { int i
= V
; V
= i
; }
329 void ExplicitAccess() { int i
= this->V
; this->V
= i
; }
331 struct SP8
: public SP7
{
332 void AccessWithQualifier() { int i
= SP7::V
; SP7::V
= i
; }
338 __declspec(property(get
=GetV
, put
=SetV
)) T V
;
339 T
GetV() { return 0; }
341 bool f() { V
= this->V
; return V
< this->V
; }
347 bool operator<(const SP10
& v
) { return true; }
348 SP10
operator*(int v
) { return *this; }
349 SP10
operator+(int v
) { return *this; }
350 SP10
& operator=(const SP10
& v
) { return *this; }
354 int i
= c
.V
; // Decl initializer
355 i
= c
.V
; // Binary op operand
356 c
.SetV(c
.V
); // CallExpr arg
357 int *p
= new int[c
.V
+ 1]; // Array size
358 p
[c
.V
] = 1; // Array index
362 c
.V
++; // Unary op operand
363 c
.V
*= 2; // Unary op operand
366 c2
.V
[0] = 123; // Array
369 c3
.f(); // Overloaded binary op operand
370 c3
.g(); // Overloaded incdec op operand
371 c3
.h(); // Overloaded unary op operand
376 int &i2
; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
379 // Property getter using reference.
381 __declspec(property(get
=GetV
)) int V
;
383 int& GetV() { return _v
; }
385 void TakePtr(int *) {}
386 void TakeRef(int &) {}
396 struct StructWithUnnamedMember
{
397 __declspec(property(get
=GetV
)) int : 10; // expected-error {{anonymous property is not supported}}
400 struct MSPropertyClass
{
401 int get() { return 42; }
402 int __declspec(property(get
= get
)) n
;
405 int *f(MSPropertyClass
&x
) {
406 return &x
.n
; // expected-error {{address of property expression requested}}
408 int MSPropertyClass::*g() {
409 return &MSPropertyClass::n
; // expected-error {{address of property expression requested}}
412 namespace rdar14250378
{
415 namespace NyNamespace
{
421 class Baz
: public Foo
{
426 Bar
* Foo::EnsureBar() {
432 // expected-error@+1 {{'sealed' keyword not permitted with interface types}}
433 __interface InterfaceWithSealed sealed
{
437 virtual void OverrideMe();
439 // expected-note@+2 {{overridden virtual function is here}}
440 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
441 virtual void SealedFunction() sealed
; // expected-note {{overridden virtual function is here}}
444 // expected-note@+2 {{'SealedType' declared here}}
445 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
446 struct SealedType sealed
: SomeBase
{
447 // expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}}
448 // FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function.
449 virtual void SealedFunction(); // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}}
451 #if __cplusplus <= 199711L
452 // expected-warning@+2 {{'override' keyword is a C++11 extension}}
454 virtual void OverrideMe() override
;
457 // expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
458 struct InheritFromSealed
: SealedType
{};
460 class SealedDestructor
{ // expected-note {{mark 'SealedDestructor' as 'sealed' to silence this warning}}
461 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
462 virtual ~SealedDestructor() sealed
; // expected-warning {{class with destructor marked 'sealed' cannot be inherited from}}
465 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
466 class AbstractClass abstract
{
470 // expected-error@+1 {{variable type 'AbstractClass' is an abstract class}}
471 AbstractClass abstractInstance
;
473 // expected-warning@+4 {{abstract class is marked 'sealed'}}
474 // expected-note@+3 {{'AbstractAndSealedClass' declared here}}
475 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
476 // expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
477 class AbstractAndSealedClass abstract sealed
{}; // Does no really make sense, but allowed
479 // expected-error@+1 {{variable type 'AbstractAndSealedClass' is an abstract class}}
480 AbstractAndSealedClass abstractAndSealedInstance
;
481 // expected-error@+1 {{base 'AbstractAndSealedClass' is marked 'sealed'}}
482 class InheritFromAbstractAndSealed
: AbstractAndSealedClass
{};
484 #if __cplusplus <= 199711L
485 // expected-warning@+4 {{'final' keyword is a C++11 extension}}
486 // expected-warning@+3 {{'final' keyword is a C++11 extension}}
488 // expected-error@+1 {{class already marked 'final'}}
489 class TooManyVirtSpecifiers1 final final
{};
490 #if __cplusplus <= 199711L
491 // expected-warning@+4 {{'final' keyword is a C++11 extension}}
493 // expected-warning@+2 {{'sealed' keyword is a Microsoft extension}}
494 // expected-error@+1 {{class already marked 'sealed'}}
495 class TooManyVirtSpecifiers2 final sealed
{};
496 #if __cplusplus <= 199711L
497 // expected-warning@+6 {{'final' keyword is a C++11 extension}}
498 // expected-warning@+5 {{'final' keyword is a C++11 extension}}
500 // expected-warning@+3 {{abstract class is marked 'final'}}
501 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
502 // expected-error@+1 {{class already marked 'final'}}
503 class TooManyVirtSpecifiers3 final abstract final
{};
504 #if __cplusplus <= 199711L
505 // expected-warning@+6 {{'final' keyword is a C++11 extension}}
507 // expected-warning@+4 {{abstract class is marked 'final'}}
508 // expected-warning@+3 {{'abstract' keyword is a Microsoft extension}}
509 // expected-warning@+2 {{'abstract' keyword is a Microsoft extension}}
510 // expected-error@+1 {{class already marked 'abstract'}}
511 class TooManyVirtSpecifiers4 abstract final abstract
{};
516 class AbstractFunctionInClass
: public Base
{
517 // expected-note@+2 {{unimplemented pure virtual method 'f' in 'AbstractFunctionInClass'}}
518 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
519 virtual void f() abstract
;
520 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
521 void g() abstract
; // expected-error {{'g' is not virtual and cannot be declared pure}}
522 // expected-note@+2 {{unimplemented pure virtual method 'h' in 'AbstractFunctionInClass'}}
523 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
524 virtual void h() abstract
= 0; // expected-error {{class member already marked 'abstract'}}
525 #if __cplusplus <= 199711L
526 // expected-warning@+4 {{'override' keyword is a C++11 extension}}
528 // expected-note@+2 {{unimplemented pure virtual method 'i' in 'AbstractFunctionInClass'}}
529 // expected-warning@+1 {{'abstract' keyword is a Microsoft extension}}
530 virtual void i() abstract override
;
533 // expected-error@+1 {{variable type 'AbstractFunctionInClass' is an abstract class}}
534 AbstractFunctionInClass abstractFunctionInClassInstance
;
536 void AfterClassBody() {
537 // expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
538 struct D
{} __declspec(deprecated
);
540 struct __declspec(align(4)) S
{} __declspec(align(8)) s1
;
542 _Static_assert(__alignof(S
) == 4, "");
543 _Static_assert(__alignof(s1
) == 8, "");
544 _Static_assert(__alignof(s2
) == 4, "");
548 template <typename TX
> struct A
{
549 template <bool> struct largest_type_select
;
550 template <> struct largest_type_select
<false> {
551 blah x
; // expected-error {{unknown type name 'blah'}}
556 class PR34109_class
{
558 virtual ~PR34109_class() {}
561 void operator delete(void *) throw();
562 // expected-note@-1 {{previous declaration is here}}
563 __declspec(dllexport
) void operator delete(void *) throw();
564 // expected-error@-1 {{redeclaration of 'operator delete' cannot add 'dllexport' attribute}}
566 void PR34109(int* a
) {
572 __attribute__((nothrow
)) void Foo(); // expected-note {{previous declaration is here}}
573 __attribute__((nothrow
)) void Bar();
575 void S::Foo(){} // expected-warning {{is missing exception specification}}
576 __attribute__((nothrow
)) void S::Bar(){}
581 // Check that __unaligned is not recognized if MS extensions are not enabled
582 typedef char __unaligned
*aligned_type
; // expected-error {{expected ';' after top level declarator}}
587 template<typename T
> struct A
{};
588 template<typename T
> struct B
: A
<A
<T
>> { A
<T
>::C::D d
; }; // expected-error {{missing 'typename' prior to dependent type name 'A<T>::C::D'}}
593 #error Unknown test mode