Compiler version and platform:
Intel(R) C Intel(R) 64 Compiler for applications running on Intel(R) 64, Version 17.0.0.098 Build 20160721
$ g++-6.2 small.cpp $ clang++-3.8 small.cpp $ $ icc small.cpp small.cpp(9): error: declaration is incompatible with function template "void S<T>::f(U) [with T=int]" (declared at line 4) template < typename U > friend void S < T >::f (U); ^ detected during: instantiation of class "C<T> [with T=int]" at line 4 instantiation of "void S<T>::f(U) [with T=int, U=double]" at line 16 small.cpp(4): error #308: member "C<T>::i [with T=int]" (declared at line 10) is inaccessible template < typename U > void f (U u) { C < T > ct; ct.i = 0; } ^ detected during instantiation of "void S<T>::f(U) [with T=int, U=double]" at line 16 compilation aborted for small.cpp (code 2) $ $ cat small.cpp template < typename T > class C; template < typename T > struct S { template < typename U > void f (U u) { C < T > ct; ct.i = 0; } }; template < typename T > class C { template < typename U > friend void S < T >::f (U); int i; }; int main () { S < int > si; si.f (0.0); return 0; } $