2 // { dg-do compile { target c++20 } }
3 // Adapted from <https://en.cppreference.com/w/cpp/types/is_convertible>.
8 #define SA(X) static_assert((X),#X)
10 class E { public: template<class T> E(T&&) { } };
15 class B : public A {};
17 class D { public: operator C() { return c; } C c; };
19 SA(__is_convertible(B*, A*));
20 SA(!__is_convertible(A*, B*));
21 SA(__is_convertible(D, C));
22 SA(!__is_convertible(B*, C*));
23 SA(__is_convertible(A, E));
25 using std::operator "" s, std::operator "" sv;
27 auto stringify = []<typename T>(T x) {
28 if constexpr (std::is_convertible_v<T, std::string> or
29 std::is_convertible_v<T, std::string_view>) {
32 return std::to_string(x);
36 const char* three = "three";
38 SA(!__is_convertible(std::string_view, std::string));
39 SA(__is_convertible(std::string, std::string_view));
41 auto s1 = stringify("one"s);
42 auto s2 = stringify("two"sv);
43 auto s3 = stringify(three);
44 auto s4 = stringify(42);
45 auto s5 = stringify(42.);