2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify %s
2008-10-31 22:43:28 +08:00
struct A { } ;
struct B : A { } ;
struct C : B { } ;
struct D : private A { } ;
struct E : A { } ;
struct F : B , E { } ;
2010-03-10 19:27:22 +08:00
struct Incomplete ; // expected-note 2 {{forward declaration of 'Incomplete'}}
2008-10-31 22:43:28 +08:00
2008-11-06 23:59:35 +08:00
struct Poly
{
virtual void f ( ) ;
} ;
struct PolyDerived : Poly
{
} ;
2008-10-31 22:43:28 +08:00
void basic_bad ( )
{
// ptr -> nonptr
2010-03-10 19:27:22 +08:00
( void ) dynamic_cast < A > ( ( A * ) 0 ) ; // expected-error {{'A' is not a reference or pointer}}
2008-10-31 22:43:28 +08:00
// 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
2010-03-10 19:27:22 +08:00
( void ) dynamic_cast < Incomplete * > ( ( A * ) 0 ) ; // expected-error {{'Incomplete' is an incomplete type}}
2008-10-31 22:43:28 +08:00
// incomplete -> ptr
2010-03-10 19:27:22 +08:00
( void ) dynamic_cast < A * > ( ( Incomplete * ) 0 ) ; // expected-error {{'Incomplete' is an incomplete type}}
2008-10-31 22:43:28 +08: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
2010-03-10 19:27:22 +08:00
( void ) dynamic_cast < A * > ( ( F * ) 0 ) ; // expected-error {{ambiguous conversion from derived class 'F' to base class '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 'F' to base class 'A':\n struct F -> struct B -> struct A\n struct F -> struct E -> struct A}}
2008-10-31 22:43:28 +08:00
}
2008-11-06 23:59:35 +08: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
2010-03-10 19:27:22 +08:00
( void ) dynamic_cast < Poly * > ( ( A * ) 0 ) ; // expected-error {{'A' is not polymorphic}}
( void ) dynamic_cast < PolyDerived & > ( * ( ( A * ) 0 ) ) ; // expected-error {{'A' is not polymorphic}}
2008-11-06 23:59:35 +08:00
}