https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58428
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- ICC rejects it with the following message: <source>(5): error: a qualified friend template declaration must refer to a specific previously declared template template <class U> friend class A<T, U>::B; ^ detected during instantiation of class "C<T> [with T=int]" at line 8 <source>(5): warning #819: template nesting depth does not match the previous declaration of template "A<T, U>::B [with T=int, U=U]" template <class U> friend class A<T, U>::B; ^ detected during instantiation of class "C<T> [with T=int]" at line 8 MSVC also rejects the code but says U is undeclared which does not make any sense. clang accepts the code.