blob: b3babf12981e4ceec133ccfd93990a62ec1be86c [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregora3a7b8e2009-05-19 19:05:47 +00002
John McCall79ab2c82011-02-14 18:34:10 +00003struct A { int x; }; // expected-note 2 {{candidate constructor}}
Douglas Gregora3a7b8e2009-05-19 19:05:47 +00004
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) {
John McCall79ab2c82011-02-14 18:34:10 +000026 (void)((U)t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
Douglas Gregora3a7b8e2009-05-19 19:05:47 +000027 }
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) {
John McCall79ab2c82011-02-14 18:34:10 +000039 (void)static_cast<U>(t); // expected-error{{no matching conversion for static_cast from 'int' to 'A'}}
Douglas Gregora3a7b8e2009-05-19 19:05:47 +000040 }
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) {
Douglas Gregord4c5f842011-04-15 17:59:54 +000066 (void)reinterpret_cast<U>(t); // expected-error{{qualifiers}}
Douglas Gregora3a7b8e2009-05-19 19:05:47 +000067 }
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) {
John McCall79ab2c82011-02-14 18:34:10 +000092 (void)U(t); // expected-error{{cannot convert 'A' to 'int' without a conversion operator}}
Douglas Gregora3a7b8e2009-05-19 19:05:47 +000093 }
94};
95
96template struct FunctionalCast1<int, float>;
97template struct FunctionalCast1<A, int>; // expected-note{{instantiation}}
98
Douglas Gregora3a7b8e2009-05-19 19:05:47 +000099// 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>;
Douglas Gregor2685eab2009-10-29 23:08:22 +0000108
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}