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