https://gcc.gnu.org/bugzilla/show_bug.cgi?id=95888
--- Comment #6 from Marek Polacek <mpolacek at gcc dot gnu.org> --- I've found out that the same issue happens with auto template parameter too, and started way before my change: template <typename T> class A { A(int, int); template <typename> friend class A; friend T; }; template<typename U> struct B { template<auto V> struct C { A<B> begin() { return {1, 0}; } }; template<auto Z, int *P = nullptr> C<Z> fn(); }; int main () { B<int> b; b.fn<1>().begin(); } this (valid) used to crash, and since r243867 we loop infinitely. I have a patch that fixes both.