| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
#if __has_builtin (__is_deducible) |
| 4 |
|
| 5 |
template <class T> struct A { }; |
| 6 |
template <class T> struct B { }; |
| 7 |
|
| 8 |
// Simple forms. |
| 9 |
static_assert (__is_deducible (::A, A<int>)); |
| 10 |
static_assert (__is_deducible (B, B<int>)); |
| 11 |
static_assert (!__is_deducible (A, B<int>)); |
| 12 |
static_assert (!__is_deducible (::B, A<int>)); |
| 13 |
|
| 14 |
// This is the interesting use case for alias CTAD. |
| 15 |
template <class T> using AP = A<T*>; |
| 16 |
static_assert (__is_deducible (AP, A<int*>)); |
| 17 |
static_assert (!__is_deducible (AP, A<int>)); |
| 18 |
|
| 19 |
// Can't deduce a parameter not used on the RHS. |
| 20 |
template <class T> using C = void; |
| 21 |
static_assert (!__is_deducible (C, C<int>)); |
| 22 |
|
| 23 |
// But a default template argument counts. |
| 24 |
template <class T = void> using D = void; |
| 25 |
static_assert (__is_deducible (D, D<int>)); |
| 26 |
|
| 27 |
// P0127 array bound type deduction should work here. |
| 28 |
template <class T, T N> using E = int[N]; |
| 29 |
static_assert (__is_deducible (E, int[42])); |
| 30 |
|
| 31 |
#endif // __has_builtin (__is_deducible) |
| 32 |
|
| 33 |
// We don't try to support this. |
| 34 |
template <class T> void f(T); |
| 35 |
bool b = __is_deducible (f, void (int)); // { dg-error "" } |