| 1 |
// { dg-do compile { target c++20 } } |
| 2 |
|
| 3 |
// Here, normal overload resolution would consider B::operator bool when |
| 4 |
// evaluating A(b), leading to a hard error instantiating Error<int>, but we |
| 5 |
// avoid considering it by noticing that converting bool (a scalar) to A (a |
| 6 |
// class) would require a user-defined conversion, which is not allowed when |
| 7 |
// we're already dealing with the user-defined conversion to A. |
| 8 |
|
| 9 |
// This seems to be allowed by [temp.inst]/9: "If the function selected by |
| 10 |
// overload resolution (12.4) can be determined without instantiating a class |
| 11 |
// template definition, it is unspecified whether that instantiation actually |
| 12 |
// takes place." |
| 13 |
|
| 14 |
template <class T> |
| 15 |
struct Error { static constexpr auto value = T::value; }; |
| 16 |
|
| 17 |
struct A { A(const A&); }; |
| 18 |
|
| 19 |
template <class T> |
| 20 |
struct B { operator bool() requires Error<T>::value; }; |
| 21 |
|
| 22 |
template <class T> |
| 23 |
concept C = requires (B<T> b) { A(b); }; |
| 24 |
|
| 25 |
static_assert(!C<int>); |