[Reland][Runtimes] Merge 'compile_commands.json' files from runtimes build (#116303)
[llvm-project.git] / clang / test / SemaTemplate / instantiate-cast.cpp
blob69aaac73b7fd66aff96e1c707d0ff95c148d9df6
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
5 struct A { int x; };
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}}
9 #endif
10 // expected-note@-5 {{candidate constructor (the implicit default constructor) not viable: requires 0 arguments, but 1 was provided}}
12 class Base {
13 public:
14 virtual void f();
17 class Derived : public Base { };
19 struct ConvertibleToInt {
20 operator int() const;
23 struct Constructible {
24 Constructible(int, float);
27 // ---------------------------------------------------------------------
28 // C-style casts
29 // ---------------------------------------------------------------------
30 template<typename T, typename U>
31 struct CStyleCast0 {
32 void f(T t) {
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 // ---------------------------------------------------------------------
41 // static_cast
42 // ---------------------------------------------------------------------
43 template<typename T, typename U>
44 struct StaticCast0 {
45 void f(T t) {
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 // ---------------------------------------------------------------------
55 // dynamic_cast
56 // ---------------------------------------------------------------------
57 template<typename T, typename U>
58 struct DynamicCast0 {
59 void f(T t) {
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 // ---------------------------------------------------------------------
68 // reinterpret_cast
69 // ---------------------------------------------------------------------
70 template<typename T, typename U>
71 struct ReinterpretCast0 {
72 void f(T t) {
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 // ---------------------------------------------------------------------
81 // const_cast
82 // ---------------------------------------------------------------------
83 template<typename T, typename U>
84 struct ConstCast0 {
85 void f(T t) {
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 {
98 void f(T t) {
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 {
109 void f() {
110 (void)Constructible(N, M);
114 template struct FunctionalCast2<1, 3>;
116 // ---------------------------------------------------------------------
117 // implicit casting
118 // ---------------------------------------------------------------------
119 template<typename T>
120 struct Derived2 : public Base { };
122 void test_derived_to_base(Base *&bp, Derived2<int> *dp) {
123 bp = dp;