1// RUN: %clang_cc1 -fsyntax-only -verify %s
2
3struct A { int x; }; // expected-note 2 {{candidate constructor}}
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); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
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{{no matching conversion for static_cast from 'int' to 'A'}}
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{{qualifiers}}
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); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
93  }
94};
95
96template struct FunctionalCast1<int, float>;
97template struct FunctionalCast1<A, int>; // expected-note{{instantiation}}
98
99// Generates temporaries, which we cannot handle yet.
100template<int N, long M>
101struct FunctionalCast2 {
102  void f() {
103    (void)Constructible(N, M);
104  }
105};
106
107template struct FunctionalCast2<1, 3>;
108
109// ---------------------------------------------------------------------
110// implicit casting
111// ---------------------------------------------------------------------
112template<typename T>
113struct Derived2 : public Base { };
114
115void test_derived_to_base(Base *&bp, Derived2<int> *dp) {
116  bp = dp;
117}
118