1 // RUN: clang -fsyntax-only -verify %s
2 
3 struct A {};
4 struct B : A {};
5 struct C : B {};
6 
7 struct D : private A {};
8 struct E : A {};
9 struct F : B, E {};
10 
11 struct Incomplete;
12 
13 void basic_bad()
14 {
15   // ptr -> nonptr
16   (void)dynamic_cast<A>((A*)0); // expected-error {{'struct A' is not a reference or pointer}}
17   // nonptr -> ptr
18   (void)dynamic_cast<A*>(0); // expected-error {{'int' is not a pointer}}
19   // ptr -> noncls
20   (void)dynamic_cast<int*>((A*)0); // expected-error {{'int' is not a class}}
21   // noncls -> ptr
22   (void)dynamic_cast<A*>((int*)0); // expected-error {{'int' is not a class}}
23   // ref -> noncls
24   (void)dynamic_cast<int&>(*((A*)0)); // expected-error {{'int' is not a class}}
25   // noncls -> ref
26   (void)dynamic_cast<A&>(*((int*)0)); // expected-error {{'int' is not a class}}
27   // ptr -> incomplete
28   (void)dynamic_cast<Incomplete*>((A*)0); // expected-error {{'struct Incomplete' is incomplete}}
29   // incomplete -> ptr
30   (void)dynamic_cast<A*>((Incomplete*)0); // expected-error {{'struct Incomplete' is incomplete}}
31 }
32 
33 void same()
34 {
35   (void)dynamic_cast<A*>((A*)0);
36   (void)dynamic_cast<A&>(*((A*)0));
37 }
38 
39 void up()
40 {
41   (void)dynamic_cast<A*>((B*)0);
42   (void)dynamic_cast<A&>(*((B*)0));
43   (void)dynamic_cast<A*>((C*)0);
44   (void)dynamic_cast<A&>(*((C*)0));
45 
46   // Inaccessible
47   //(void)dynamic_cast<A*>((D*)0);
48   //(void)dynamic_cast<A&>(*((D*)0));
49 
50   // Ambiguous
51   (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}}
52   (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}}
53 }
54 
55 // FIXME: Other test cases require recognition of polymorphic classes.
56