blob: 0a4dbc2ae93b847b7690e1fd998333399475100f [file] [log] [blame]
Sebastian Redl07779722008-10-31 14:43:28 +00001// RUN: clang -fsyntax-only -verify %s
2
3struct A {};
4struct B : A {};
5struct C : B {};
6
7struct D : private A {};
8struct E : A {};
9struct F : B, E {};
10
11struct Incomplete;
12
13void 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
33void same()
34{
35 (void)dynamic_cast<A*>((A*)0);
36 (void)dynamic_cast<A&>(*((A*)0));
37}
38
39void 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.