2012-11-02 09:34:28 +08:00
// RUN: %clang_cc1 %s -triple i686-pc-win32 -fsyntax-only -Wmicrosoft -Wc++11-extensions -Wno-long-long -verify -fms-extensions -fexceptions -fcxx-exceptions
2010-08-30 22:44:26 +08:00
2011-03-20 07:05:18 +08:00
// Microsoft doesn't validate exception specification.
2011-05-24 10:11:43 +08:00
namespace microsoft_exception_spec {
2011-03-20 07:05:18 +08:00
void foo ( ) ; // expected-note {{previous declaration}}
void foo ( ) throw ( ) ; // expected-warning {{exception specification in declaration does not match previous declaration}}
2010-08-30 23:04:51 +08:00
2011-03-20 07:05:18 +08:00
void r6 ( ) throw ( . . . ) ; // expected-note {{previous declaration}}
void r6 ( ) throw ( int ) ; // expected-warning {{exception specification in declaration does not match previous declaration}}
2010-08-30 23:04:51 +08:00
struct Base {
virtual void f2 ( ) ;
virtual void f3 ( ) throw ( . . . ) ;
} ;
struct Derived : Base {
virtual void f2 ( ) throw ( . . . ) ;
virtual void f3 ( ) ;
} ;
2010-09-02 00:29:03 +08:00
2011-05-24 10:11:43 +08:00
class A {
virtual ~ A ( ) throw ( ) ; // expected-note {{overridden virtual function is here}}
} ;
class B : public A {
virtual ~ B ( ) ; // expected-warning {{exception specification of overriding function is more lax than base version}}
} ;
}
2010-09-08 19:32:25 +08:00
// MSVC allows type definition in anonymous union and struct
struct A
{
2013-12-27 02:30:57 +08:00
union
2010-09-08 19:32:25 +08:00
{
int a ;
struct B // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
2013-12-27 02:30:57 +08:00
{
2010-09-08 19:32:25 +08:00
int c ;
} d ;
union C // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
{
int e ;
int ee ;
} f ;
typedef int D ; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
struct F ; // expected-warning {{types declared in an anonymous union are a Microsoft extension}}
} ;
struct
{
int a2 ;
struct B2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
{
int c2 ;
} d2 ;
2013-12-27 02:30:57 +08:00
2010-09-08 19:32:25 +08:00
union C2 // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
{
int e2 ;
int ee2 ;
} f2 ;
typedef int D2 ; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
struct F2 ; // expected-warning {{types declared in an anonymous struct are a Microsoft extension}}
} ;
} ;
2010-09-02 00:29:03 +08:00
// __stdcall handling
struct M {
int __stdcall addP ( ) ;
2013-12-27 02:30:57 +08:00
float __stdcall subtractP ( ) ;
2010-09-02 00:29:03 +08:00
} ;
2011-08-18 17:59:55 +08:00
// __unaligned handling
typedef char __unaligned * aligned_type ;
2014-12-05 07:30:25 +08:00
typedef struct UnalignedTag { int f ; } __unaligned * aligned_type2 ;
2011-08-18 17:59:55 +08:00
2010-09-02 00:29:03 +08:00
template < typename T > void h1 ( T ( __stdcall M : : * const ) ( ) ) { }
void m1 ( ) {
h1 < int > ( & M : : addP ) ;
h1 ( & M : : subtractP ) ;
2013-12-27 02:30:57 +08:00
}
2010-09-12 13:06:55 +08:00
2010-10-18 23:01:13 +08:00
2011-01-17 09:08:01 +08:00
void f ( long long ) ;
void f ( int ) ;
2013-12-27 02:30:57 +08:00
2011-01-17 09:08:01 +08:00
int main ( )
{
// This is an ambiguous call in standard C++.
// This calls f(long long) in Microsoft mode because LL is always signed.
f ( 0xffffffffffffffffLL ) ;
f ( 0xffffffffffffffff i64 ) ;
}
2011-02-23 04:32:04 +08:00
// Enumeration types with a fixed underlying type.
const int seventeen = 17 ;
typedef int Int ;
struct X0 {
2012-11-02 09:34:28 +08:00
enum E1 : Int { SomeOtherValue } field ; // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}}
2011-02-23 04:32:04 +08:00
enum E1 : seventeen ;
} ;
2012-11-02 09:34:28 +08:00
enum : long long { // expected-warning{{enumeration types with a fixed underlying type are a C++11 extension}}
2011-02-23 04:32:04 +08:00
SomeValue = 0x100000000
} ;
2011-03-29 18:39:17 +08:00
class AAA {
__declspec ( dllimport ) void f ( void ) { }
2014-03-31 22:56:15 +08:00
void f2 ( void ) ; // expected-note{{previous declaration is here}}
2011-03-29 18:39:17 +08:00
} ;
2014-05-16 06:07:49 +08:00
__declspec ( dllimport ) void AAA : : f2 ( void ) { // expected-error{{dllimport cannot be applied to non-inline function definition}}
2014-03-31 22:56:15 +08:00
// expected-error@-1{{redeclaration of 'AAA::f2' cannot add 'dllimport' attribute}}
2011-03-29 18:39:17 +08:00
}
2011-04-10 11:03:52 +08:00
template < class T >
class BB {
public :
void f ( int g = 10 ) ; // expected-note {{previous definition is here}}
} ;
template < class T >
void BB < T > : : f ( int g = 0 ) { } // expected-warning {{redefinition of default argument}}
2011-04-13 10:38:49 +08:00
2011-04-22 16:14:00 +08:00
extern void static_func ( ) ;
void static_func ( ) ; // expected-note {{previous declaration is here}}
2014-06-19 07:26:25 +08:00
static void static_func ( ) / / expected - warning { { redeclaring non - static ' static_func ' as static is a Microsoft extension } }
2011-04-22 16:14:00 +08:00
{
2011-05-09 06:52:41 +08:00
}
2014-06-19 07:26:25 +08:00
extern const int static_var ; // expected-note {{previous declaration is here}}
static const int static_var = 3 ; // expected-warning {{redeclaring non-static 'static_var' as static is a Microsoft extension}}
2011-05-09 06:52:41 +08:00
long function_prototype ( int a ) ;
long ( * function_ptr ) ( int a ) ;
void function_to_voidptr_conv ( ) {
void * a1 = function_prototype ;
void * a2 = & function_prototype ;
2011-05-09 07:15:10 +08:00
void * a3 = function_ptr ;
2011-05-09 06:52:41 +08:00
}
2011-05-12 06:13:54 +08:00
void pointer_to_integral_type_conv ( char * ptr ) {
char ch = ( char ) ptr ;
short sh = ( short ) ptr ;
ch = ( char ) ptr ;
sh = ( short ) ptr ;
2011-05-23 11:43:44 +08:00
2013-06-06 17:16:36 +08:00
// These are valid C++.
bool b = ( bool ) ptr ;
b = static_cast < bool > ( ptr ) ;
// This is bad.
b = reinterpret_cast < bool > ( ptr ) ; // expected-error {{cast from pointer to smaller type 'bool' loses information}}
}
2011-06-01 12:14:20 +08:00
2011-10-18 01:09:53 +08:00
struct PR11150 {
class X {
virtual void f ( ) = 0 ;
} ;
int array [ __is_abstract ( X ) ? 1 : - 1 ] ;
} ;
2011-10-21 11:57:52 +08:00
void f ( ) { int __except = 0 ; }
2012-09-14 04:16:20 +08:00
void : : f ( ) ; // expected-warning{{extra qualification on member 'f'}}
2013-02-13 01:27:41 +08:00
class C {
C : : C ( ) ; // expected-warning{{extra qualification on member 'C'}}
} ;
2013-04-16 15:28:30 +08:00
struct StructWithProperty {
__declspec ( property ( get = GetV ) ) int V1 ;
__declspec ( property ( put = SetV ) ) int V2 ;
__declspec ( property ( get = GetV , put = SetV_NotExist ) ) int V3 ;
__declspec ( property ( get = GetV_NotExist , put = SetV ) ) int V4 ;
__declspec ( property ( get = GetV , put = SetV ) ) int V5 ;
int GetV ( ) { return 123 ; }
void SetV ( int i ) { }
} ;
void TestProperty ( ) {
StructWithProperty sp ;
int i = sp . V2 ; // expected-error{{no getter defined for property 'V2'}}
sp . V1 = 12 ; // expected-error{{no setter defined for property 'V1'}}
int j = sp . V4 ; // expected-error{{no member named 'GetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable getter for property 'V4'}}
sp . V3 = 14 ; // expected-error{{no member named 'SetV_NotExist' in 'StructWithProperty'}} expected-error{{cannot find suitable setter for property 'V3'}}
int k = sp . V5 ;
sp . V5 = k + + ;
}
/* 4 tests for PseudoObject, begin */
struct SP1
{
bool operator ( ) ( ) { return true ; }
} ;
struct SP2
{
__declspec ( property ( get = GetV ) ) SP1 V ;
SP1 GetV ( ) { return SP1 ( ) ; }
} ;
void TestSP2 ( ) {
SP2 sp2 ;
bool b = sp2 . V ( ) ;
}
struct SP3 {
template < class T >
void f ( T t ) { }
} ;
template < class T >
struct SP4
{
__declspec ( property ( get = GetV ) ) int V ;
int GetV ( ) { return 123 ; }
void f ( ) { SP3 s2 ; s2 . f ( V ) ; }
} ;
void TestSP4 ( ) {
SP4 < int > s ;
s . f ( ) ;
}
template < class T >
struct SP5
{
__declspec ( property ( get = GetV ) ) T V ;
int GetV ( ) { return 123 ; }
void f ( ) { int * p = new int [ V ] ; }
} ;
template < class T >
struct SP6
{
public :
__declspec ( property ( get = GetV ) ) T V ;
T GetV ( ) { return 123 ; }
void f ( ) { int t = V ; }
} ;
void TestSP6 ( ) {
SP6 < int > c ;
c . f ( ) ;
}
/* 4 tests for PseudoObject, end */
// Property access: explicit, implicit, with Qualifier
struct SP7 {
__declspec ( property ( get = GetV , put = SetV ) ) int V ;
int GetV ( ) { return 123 ; }
void SetV ( int v ) { }
void ImplicitAccess ( ) { int i = V ; V = i ; }
void ExplicitAccess ( ) { int i = this - > V ; this - > V = i ; }
} ;
struct SP8 : public SP7 {
void AccessWithQualifier ( ) { int i = SP7 : : V ; SP7 : : V = i ; }
} ;
// Property usage
template < class T >
struct SP9 {
__declspec ( property ( get = GetV , put = SetV ) ) T V ;
T GetV ( ) { return 0 ; }
void SetV ( T v ) { }
2014-03-11 11:11:08 +08:00
bool f ( ) { V = this - > V ; return V < this - > V ; }
2013-04-17 06:32:04 +08:00
void g ( ) { V + + ; }
void h ( ) { V * = 2 ; }
2013-04-16 15:28:30 +08:00
} ;
struct SP10 {
SP10 ( int v ) { }
bool operator < ( const SP10 & v ) { return true ; }
SP10 operator * ( int v ) { return * this ; }
2013-04-17 06:32:04 +08:00
SP10 operator + ( int v ) { return * this ; }
2013-04-16 15:28:30 +08:00
SP10 & operator = ( const SP10 & v ) { return * this ; }
} ;
void TestSP9 ( ) {
SP9 < int > c ;
int i = c . V ; // Decl initializer
i = c . V ; // Binary op operand
c . SetV ( c . V ) ; // CallExpr arg
int * p = new int [ c . V + 1 ] ; // Array size
p [ c . V ] = 1 ; // Array index
c . V = 123 ; // Setter
c . V + + ; // Unary op operand
c . V * = 2 ; // Unary op operand
SP9 < int * > c2 ;
c2 . V [ 0 ] = 123 ; // Array
SP9 < SP10 > c3 ;
c3 . f ( ) ; // Overloaded binary op operand
2013-04-17 06:32:04 +08:00
c3 . g ( ) ; // Overloaded incdec op operand
c3 . h ( ) ; // Overloaded unary op operand
2013-04-16 15:28:30 +08:00
}
2013-05-31 00:20:00 +08:00
union u {
int * i1 ;
int & i2 ; // expected-warning {{union member 'i2' has reference type 'int &', which is a Microsoft extension}}
} ;
2013-06-20 00:37:23 +08:00
// Property getter using reference.
struct SP11 {
__declspec ( property ( get = GetV ) ) int V ;
int _v ;
int & GetV ( ) { return _v ; }
void UseV ( ) ;
void TakePtr ( int * ) { }
void TakeRef ( int & ) { }
void TakeVal ( int ) { }
} ;
void SP11 : : UseV ( ) {
TakePtr ( & V ) ;
TakeRef ( V ) ;
TakeVal ( V ) ;
}
2013-06-27 05:28:44 +08:00
struct StructWithUnnamedMember {
__declspec ( property ( get = GetV ) ) int : 10 ; // expected-error {{anonymous property is not supported}}
} ;
2013-06-28 04:42:30 +08:00
2015-02-25 04:29:40 +08:00
struct MSPropertyClass {
int get ( ) { return 42 ; }
int __declspec ( property ( get = get ) ) n ;
} ;
int * f ( MSPropertyClass & x ) {
return & x . n ; // expected-error {{address of property expression requested}}
}
int MSPropertyClass : : * g ( ) {
return & MSPropertyClass : : n ; // expected-error {{address of property expression requested}}
}
2013-06-28 04:42:30 +08:00
namespace rdar14250378 {
class Bar { } ;
2013-12-27 02:30:57 +08:00
2013-06-28 04:42:30 +08:00
namespace NyNamespace {
class Foo {
public :
Bar * EnsureBar ( ) ;
} ;
2013-12-27 02:30:57 +08:00
2013-06-28 04:42:30 +08:00
class Baz : public Foo {
public :
friend class Bar ;
} ;
2013-12-27 02:30:57 +08:00
2013-06-28 04:42:30 +08:00
Bar * Foo : : EnsureBar ( ) {
return 0 ;
}
}
}
2013-10-18 08:33:31 +08:00
// expected-error@+1 {{'sealed' keyword not permitted with interface types}}
__interface InterfaceWithSealed sealed {
} ;
struct SomeBase {
virtual void OverrideMe ( ) ;
// expected-note@+2 {{overridden virtual function is here}}
// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
2014-10-28 03:11:51 +08:00
virtual void SealedFunction ( ) sealed ; // expected-note {{overridden virtual function is here}}
2013-10-18 08:33:31 +08:00
} ;
// expected-note@+2 {{'SealedType' declared here}}
// expected-warning@+1 {{'sealed' keyword is a Microsoft extension}}
struct SealedType sealed : SomeBase {
2014-10-28 03:11:51 +08:00
// expected-error@+2 {{declaration of 'SealedFunction' overrides a 'sealed' function}}
// FIXME. warning can be suppressed if we're also issuing error for overriding a 'final' function.
virtual void SealedFunction ( ) ; // expected-warning {{'SealedFunction' overrides a member function but is not marked 'override'}}
2013-10-18 08:33:31 +08:00
// expected-warning@+1 {{'override' keyword is a C++11 extension}}
virtual void OverrideMe ( ) override ;
} ;
// expected-error@+1 {{base 'SealedType' is marked 'sealed'}}
struct InheritFromSealed : SealedType { } ;
2013-11-25 04:24:54 +08:00
void AfterClassBody ( ) {
// expected-warning@+1 {{attribute 'deprecated' is ignored, place it after "struct" to apply attribute to type declaration}}
struct D { } __declspec ( deprecated ) ;
struct __declspec ( align ( 4 ) ) S { } __declspec ( align ( 8 ) ) s1 ;
S s2 ;
_Static_assert ( __alignof ( S ) = = 4 , " " ) ;
_Static_assert ( __alignof ( s1 ) = = 8 , " " ) ;
_Static_assert ( __alignof ( s2 ) = = 4 , " " ) ;
}