[Bug c++/104873] Bug in overload resolution for constrained class templates with deduction guides
ppalka at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Fri Mar 11 16:47:05 GMT 2022
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104873
Patrick Palka <ppalka at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |ppalka at gcc dot gnu.org
--- Comment #1 from Patrick Palka <ppalka at gcc dot gnu.org> ---
Reduced testcase:
template<class T> concept C = true;
template<class T> requires C<T>
struct S {
S(...);
};
template<class T> S(S<T>) -> S<S<T>>;
using type = decltype(S(S<int>()));
using type = S<int>; // Clang accepts, GCC demands S<S<int>>
The difference is that the copy deduction candidate generated by GCC is
unconstrained:
template<class T> S(S<T>) -> S<T>;
whereas Clang presumably attaches the constraints of the class template to the
candidate:
template<class T> requires C<T> S(S<T>) -> S<T>;
This also occurs for guides synthesized from a constructor:
template<class T> concept C = true;
template<class T> requires C<T>
struct S {
S();
S(T); // #1
};
template<class T> S(T) -> S<S<T>>; // #2
using type = decltype(S(0)); // Clang selects guide for #1, GCC selects #2
using type = S<int>; // therefore Clang accepts, GCC demands S<S<int>>
Is it true that a deduction guide inherits the constraints of the class
template? It's not clear to me according to [over.match.class.deduct].
More information about the Gcc-bugs
mailing list