blob: d99f3e556602d5fc99a537f15f0179862fd3e2ea [file] [log] [blame]
Douglas Gregora3a7b8e2009-05-19 19:05:47 +00001// RUN: clang-cc -fsyntax-only -verify %s
2
3struct A { int x; };
4
5class Base {
6public:
7 virtual void f();
8};
9
10class Derived : public Base { };
11
12struct ConvertibleToInt {
13 operator int() const;
14};
15
16struct Constructible {
17 Constructible(int, float);
18};
19
20// ---------------------------------------------------------------------
21// C-style casts
22// ---------------------------------------------------------------------
23template<typename T, typename U>
24struct CStyleCast0 {
25 void f(T t) {
26 (void)((U)t); // FIXME:ugly expected-error{{operand}}
27 }
28};
29
30template struct CStyleCast0<int, float>;
31template struct CStyleCast0<A, int>; // expected-note{{instantiation}}
32
33// ---------------------------------------------------------------------
34// static_cast
35// ---------------------------------------------------------------------
36template<typename T, typename U>
37struct StaticCast0 {
38 void f(T t) {
39 (void)static_cast<U>(t); // expected-error{{static_cast}}
40 }
41};
42
43template struct StaticCast0<ConvertibleToInt, bool>;
44template struct StaticCast0<int, float>;
45template struct StaticCast0<int, A>; // expected-note{{instantiation}}
46
47// ---------------------------------------------------------------------
48// dynamic_cast
49// ---------------------------------------------------------------------
50template<typename T, typename U>
51struct DynamicCast0 {
52 void f(T t) {
53 (void)dynamic_cast<U>(t); // expected-error{{not a reference or pointer}}
54 }
55};
56
57template struct DynamicCast0<Base*, Derived*>;
58template struct DynamicCast0<Base*, A>; // expected-note{{instantiation}}
59
60// ---------------------------------------------------------------------
61// reinterpret_cast
62// ---------------------------------------------------------------------
63template<typename T, typename U>
64struct ReinterpretCast0 {
65 void f(T t) {
66 (void)reinterpret_cast<U>(t); // expected-error{{constness}}
67 }
68};
69
70template struct ReinterpretCast0<void (*)(int), void (*)(float)>;
71template struct ReinterpretCast0<int const *, float *>; // expected-note{{instantiation}}
72
73// ---------------------------------------------------------------------
74// const_cast
75// ---------------------------------------------------------------------
76template<typename T, typename U>
77struct ConstCast0 {
78 void f(T t) {
79 (void)const_cast<U>(t); // expected-error{{not allowed}}
80 }
81};
82
83template struct ConstCast0<int const * *, int * *>;
84template struct ConstCast0<int const *, float *>; // expected-note{{instantiation}}
85
86// ---------------------------------------------------------------------
87// C++ functional cast
88// ---------------------------------------------------------------------
89template<typename T, typename U>
90struct FunctionalCast1 {
91 void f(T t) {
92 (void)U(t); // FIXME:ugly expected-error{{operand}}
93 }
94};
95
96template struct FunctionalCast1<int, float>;
97template struct FunctionalCast1<A, int>; // expected-note{{instantiation}}
98
99#if 0
100// Generates temporaries, which we cannot handle yet.
101template<int N, long M>
102struct FunctionalCast2 {
103 void f() {
104 (void)Constructible(N, M);
105 }
106};
107
108template struct FunctionalCast2<1, 3>;
109#endif