2008-10-31 17:43:28 +03:00
// RUN: clang -fsyntax-only -verify %s
struct A { } ;
struct B : A { } ;
struct C : B { } ;
struct D : private A { } ;
struct E : A { } ;
struct F : B , E { } ;
struct Incomplete ;
2008-11-06 18:59:35 +03:00
struct Poly
{
virtual void f ( ) ;
} ;
struct PolyDerived : Poly
{
} ;
2008-10-31 17:43:28 +03:00
void basic_bad ( )
{
// ptr -> nonptr
( void ) dynamic_cast < A > ( ( A * ) 0 ) ; // expected-error {{'struct A' is not a reference or pointer}}
// nonptr -> ptr
( void ) dynamic_cast < A * > ( 0 ) ; // expected-error {{'int' is not a pointer}}
// ptr -> noncls
( void ) dynamic_cast < int * > ( ( A * ) 0 ) ; // expected-error {{'int' is not a class}}
// noncls -> ptr
( void ) dynamic_cast < A * > ( ( int * ) 0 ) ; // expected-error {{'int' is not a class}}
// ref -> noncls
( void ) dynamic_cast < int & > ( * ( ( A * ) 0 ) ) ; // expected-error {{'int' is not a class}}
// noncls -> ref
( void ) dynamic_cast < A & > ( * ( ( int * ) 0 ) ) ; // expected-error {{'int' is not a class}}
// ptr -> incomplete
2008-11-24 09:25:27 +03:00
( void ) dynamic_cast < Incomplete * > ( ( A * ) 0 ) ; // expected-error {{'struct Incomplete' is an incomplete type}}
2008-10-31 17:43:28 +03:00
// incomplete -> ptr
2008-11-24 09:25:27 +03:00
( void ) dynamic_cast < A * > ( ( Incomplete * ) 0 ) ; // expected-error {{'struct Incomplete' is an incomplete type}}
2008-10-31 17:43:28 +03:00
}
void same ( )
{
( void ) dynamic_cast < A * > ( ( A * ) 0 ) ;
( void ) dynamic_cast < A & > ( * ( ( A * ) 0 ) ) ;
}
void up ( )
{
( void ) dynamic_cast < A * > ( ( B * ) 0 ) ;
( void ) dynamic_cast < A & > ( * ( ( B * ) 0 ) ) ;
( void ) dynamic_cast < A * > ( ( C * ) 0 ) ;
( void ) dynamic_cast < A & > ( * ( ( C * ) 0 ) ) ;
// Inaccessible
//(void)dynamic_cast<A*>((D*)0);
//(void)dynamic_cast<A&>(*((D*)0));
// Ambiguous
( void ) dynamic_cast < A * > ( ( F * ) 0 ) ; // expected-error {{ambiguous conversion from derived class 'struct F' to base class 'struct A':\n struct F -> struct B -> struct A\n struct F -> struct E -> struct A}}
( void ) dynamic_cast < A & > ( * ( ( F * ) 0 ) ) ; // expected-error {{ambiguous conversion from derived class 'struct F' to base class 'struct A':\n struct F -> struct B -> struct A\n struct F -> struct E -> struct A}}
}
2008-11-06 18:59:35 +03:00
void poly ( )
{
( void ) dynamic_cast < A * > ( ( Poly * ) 0 ) ;
( void ) dynamic_cast < A & > ( * ( ( Poly * ) 0 ) ) ;
( void ) dynamic_cast < A * > ( ( PolyDerived * ) 0 ) ;
( void ) dynamic_cast < A & > ( * ( ( PolyDerived * ) 0 ) ) ;
// Not polymorphic source
( void ) dynamic_cast < Poly * > ( ( A * ) 0 ) ; // expected-error {{'struct A' is not polymorphic}}
( void ) dynamic_cast < PolyDerived & > ( * ( ( A * ) 0 ) ) ; // expected-error {{'struct A' is not polymorphic}}
}