clang compiles this code, printing 1000. I don't know how that is possible!
VS2013 doesn't compile it, as I was expecting.
#include <iostream> template <class T> void f(T); namespace A { struct X { class Y { friend void f<>(int); static const int i = 1000; }; }; } template <class T> void f(T t) { std::cout << A::X::Y::i << '\n'; } int main() { f(10); }
If I transfer the template declaration and the definition into the namespace A, as shown below, then VS2013 works correctly printing 1000, because now the function A::f() is a friend of the class A::Y::X.
#include <iostream> namespace A { template <class T> void f(T); struct X { class Y { friend void f<>(int); static const int i = 1000; }; }; template <class T> void f(T t) { std::cout << A::X::Y::i << '\n'; } } int main() { A::f(10); }