1 // RUN: %clang_cc1 -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
6 // expected-note@-1 {{candidate constructor (the implicit copy constructor) not viable: no known conversion from 'int' to 'const A' for 1st argument}}
7 #if __cplusplus >= 201103L
8 // expected-note@-3 {{candidate constructor (the implicit move constructor) not viable: no known conversion from 'int' to 'A' for 1st argument}}
10 // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
17 class Derived
: public Base
{ };
19 struct ConvertibleToInt
{
23 struct Constructible
{
24 Constructible(int, float);
27 // ---------------------------------------------------------------------
29 // ---------------------------------------------------------------------
30 template<typename T
, typename U
>
33 (void)((U
)t
); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
37 template struct CStyleCast0
<int, float>;
38 template struct CStyleCast0
<A
, int>; // expected-note{{instantiation}}
40 // ---------------------------------------------------------------------
42 // ---------------------------------------------------------------------
43 template<typename T
, typename U
>
46 (void)static_cast<U
>(t
); // expected-error{{no matching conversion for static_cast from 'int' to 'A'}}
50 template struct StaticCast0
<ConvertibleToInt
, bool>;
51 template struct StaticCast0
<int, float>;
52 template struct StaticCast0
<int, A
>; // expected-note{{instantiation}}
54 // ---------------------------------------------------------------------
56 // ---------------------------------------------------------------------
57 template<typename T
, typename U
>
60 (void)dynamic_cast<U
>(t
); // expected-error{{invalid target type 'A' for dynamic_cast; target type must be a reference or pointer type to a defined class}}
64 template struct DynamicCast0
<Base
*, Derived
*>;
65 template struct DynamicCast0
<Base
*, A
>; // expected-note{{instantiation}}
67 // ---------------------------------------------------------------------
69 // ---------------------------------------------------------------------
70 template<typename T
, typename U
>
71 struct ReinterpretCast0
{
73 (void)reinterpret_cast<U
>(t
); // expected-error{{qualifiers}}
77 template struct ReinterpretCast0
<void (*)(int), void (*)(float)>;
78 template struct ReinterpretCast0
<int const *, float *>; // expected-note{{instantiation}}
80 // ---------------------------------------------------------------------
82 // ---------------------------------------------------------------------
83 template<typename T
, typename U
>
86 (void)const_cast<U
>(t
); // expected-error{{not allowed}}
90 template struct ConstCast0
<int const * *, int * *>;
91 template struct ConstCast0
<int const *, float *>; // expected-note{{instantiation}}
93 // ---------------------------------------------------------------------
94 // C++ functional cast
95 // ---------------------------------------------------------------------
96 template<typename T
, typename U
>
97 struct FunctionalCast1
{
99 (void)U(t
); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
103 template struct FunctionalCast1
<int, float>;
104 template struct FunctionalCast1
<A
, int>; // expected-note{{instantiation}}
106 // Generates temporaries, which we cannot handle yet.
107 template<int N
, long M
>
108 struct FunctionalCast2
{
110 (void)Constructible(N
, M
);
114 template struct FunctionalCast2
<1, 3>;
116 // ---------------------------------------------------------------------
118 // ---------------------------------------------------------------------
120 struct Derived2
: public Base
{ };
122 void test_derived_to_base(Base
*&bp
, Derived2
<int> *dp
) {