https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103096
--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> --- (In reply to Jonathan Wakely from comment #5) > (In reply to Jonathan Wakely from comment #4) > > Maybe the compiler could notice that there is only one qHash function > > template, and so realize that the instantiation recursion of qHash<X> > > instantiating qHash<Y> instantiating qHash<Z> etc. will never terminate. > > It would also have to consider whether there are partial or explicit > specializations of the pair class template, because otherwise one of them > could define a friend that would be found by ADL and terminate the > recursion. So maybe too hard. And if-constexpr means you can't just detect the recursion based on whether name lookup finds more than one candidate: template <typename T> int qHash(const T& a) { if constexpr (delved too deep) return balrog; return qHash(pair<T, T>(a, a)); } This one will terminate, even though it keeps calling itself.