1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fsyntax-only -verify %s
2*f4a2713aSLionel Sambuc
3*f4a2713aSLionel Sambuc struct A { int x; }; // expected-note 2 {{candidate constructor}}
4*f4a2713aSLionel Sambuc
5*f4a2713aSLionel Sambuc class Base {
6*f4a2713aSLionel Sambuc public:
7*f4a2713aSLionel Sambuc virtual void f();
8*f4a2713aSLionel Sambuc };
9*f4a2713aSLionel Sambuc
10*f4a2713aSLionel Sambuc class Derived : public Base { };
11*f4a2713aSLionel Sambuc
12*f4a2713aSLionel Sambuc struct ConvertibleToInt {
13*f4a2713aSLionel Sambuc operator int() const;
14*f4a2713aSLionel Sambuc };
15*f4a2713aSLionel Sambuc
16*f4a2713aSLionel Sambuc struct Constructible {
17*f4a2713aSLionel Sambuc Constructible(int, float);
18*f4a2713aSLionel Sambuc };
19*f4a2713aSLionel Sambuc
20*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
21*f4a2713aSLionel Sambuc // C-style casts
22*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
23*f4a2713aSLionel Sambuc template<typename T, typename U>
24*f4a2713aSLionel Sambuc struct CStyleCast0 {
fCStyleCast025*f4a2713aSLionel Sambuc void f(T t) {
26*f4a2713aSLionel Sambuc (void)((U)t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
27*f4a2713aSLionel Sambuc }
28*f4a2713aSLionel Sambuc };
29*f4a2713aSLionel Sambuc
30*f4a2713aSLionel Sambuc template struct CStyleCast0<int, float>;
31*f4a2713aSLionel Sambuc template struct CStyleCast0<A, int>; // expected-note{{instantiation}}
32*f4a2713aSLionel Sambuc
33*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
34*f4a2713aSLionel Sambuc // static_cast
35*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
36*f4a2713aSLionel Sambuc template<typename T, typename U>
37*f4a2713aSLionel Sambuc struct StaticCast0 {
fStaticCast038*f4a2713aSLionel Sambuc void f(T t) {
39*f4a2713aSLionel Sambuc (void)static_cast<U>(t); // expected-error{{no matching conversion for static_cast from 'int' to 'A'}}
40*f4a2713aSLionel Sambuc }
41*f4a2713aSLionel Sambuc };
42*f4a2713aSLionel Sambuc
43*f4a2713aSLionel Sambuc template struct StaticCast0<ConvertibleToInt, bool>;
44*f4a2713aSLionel Sambuc template struct StaticCast0<int, float>;
45*f4a2713aSLionel Sambuc template struct StaticCast0<int, A>; // expected-note{{instantiation}}
46*f4a2713aSLionel Sambuc
47*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
48*f4a2713aSLionel Sambuc // dynamic_cast
49*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
50*f4a2713aSLionel Sambuc template<typename T, typename U>
51*f4a2713aSLionel Sambuc struct DynamicCast0 {
fDynamicCast052*f4a2713aSLionel Sambuc void f(T t) {
53*f4a2713aSLionel Sambuc (void)dynamic_cast<U>(t); // expected-error{{not a reference or pointer}}
54*f4a2713aSLionel Sambuc }
55*f4a2713aSLionel Sambuc };
56*f4a2713aSLionel Sambuc
57*f4a2713aSLionel Sambuc template struct DynamicCast0<Base*, Derived*>;
58*f4a2713aSLionel Sambuc template struct DynamicCast0<Base*, A>; // expected-note{{instantiation}}
59*f4a2713aSLionel Sambuc
60*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
61*f4a2713aSLionel Sambuc // reinterpret_cast
62*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
63*f4a2713aSLionel Sambuc template<typename T, typename U>
64*f4a2713aSLionel Sambuc struct ReinterpretCast0 {
fReinterpretCast065*f4a2713aSLionel Sambuc void f(T t) {
66*f4a2713aSLionel Sambuc (void)reinterpret_cast<U>(t); // expected-error{{qualifiers}}
67*f4a2713aSLionel Sambuc }
68*f4a2713aSLionel Sambuc };
69*f4a2713aSLionel Sambuc
70*f4a2713aSLionel Sambuc template struct ReinterpretCast0<void (*)(int), void (*)(float)>;
71*f4a2713aSLionel Sambuc template struct ReinterpretCast0<int const *, float *>; // expected-note{{instantiation}}
72*f4a2713aSLionel Sambuc
73*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
74*f4a2713aSLionel Sambuc // const_cast
75*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
76*f4a2713aSLionel Sambuc template<typename T, typename U>
77*f4a2713aSLionel Sambuc struct ConstCast0 {
fConstCast078*f4a2713aSLionel Sambuc void f(T t) {
79*f4a2713aSLionel Sambuc (void)const_cast<U>(t); // expected-error{{not allowed}}
80*f4a2713aSLionel Sambuc }
81*f4a2713aSLionel Sambuc };
82*f4a2713aSLionel Sambuc
83*f4a2713aSLionel Sambuc template struct ConstCast0<int const * *, int * *>;
84*f4a2713aSLionel Sambuc template struct ConstCast0<int const *, float *>; // expected-note{{instantiation}}
85*f4a2713aSLionel Sambuc
86*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
87*f4a2713aSLionel Sambuc // C++ functional cast
88*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
89*f4a2713aSLionel Sambuc template<typename T, typename U>
90*f4a2713aSLionel Sambuc struct FunctionalCast1 {
fFunctionalCast191*f4a2713aSLionel Sambuc void f(T t) {
92*f4a2713aSLionel Sambuc (void)U(t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
93*f4a2713aSLionel Sambuc }
94*f4a2713aSLionel Sambuc };
95*f4a2713aSLionel Sambuc
96*f4a2713aSLionel Sambuc template struct FunctionalCast1<int, float>;
97*f4a2713aSLionel Sambuc template struct FunctionalCast1<A, int>; // expected-note{{instantiation}}
98*f4a2713aSLionel Sambuc
99*f4a2713aSLionel Sambuc // Generates temporaries, which we cannot handle yet.
100*f4a2713aSLionel Sambuc template<int N, long M>
101*f4a2713aSLionel Sambuc struct FunctionalCast2 {
fFunctionalCast2102*f4a2713aSLionel Sambuc void f() {
103*f4a2713aSLionel Sambuc (void)Constructible(N, M);
104*f4a2713aSLionel Sambuc }
105*f4a2713aSLionel Sambuc };
106*f4a2713aSLionel Sambuc
107*f4a2713aSLionel Sambuc template struct FunctionalCast2<1, 3>;
108*f4a2713aSLionel Sambuc
109*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
110*f4a2713aSLionel Sambuc // implicit casting
111*f4a2713aSLionel Sambuc // ---------------------------------------------------------------------
112*f4a2713aSLionel Sambuc template<typename T>
113*f4a2713aSLionel Sambuc struct Derived2 : public Base { };
114*f4a2713aSLionel Sambuc
test_derived_to_base(Base * & bp,Derived2<int> * dp)115*f4a2713aSLionel Sambuc void test_derived_to_base(Base *&bp, Derived2<int> *dp) {
116*f4a2713aSLionel Sambuc bp = dp;
117*f4a2713aSLionel Sambuc }
118