The following example fails to compile in Visual Studio 2015:
namespace ns {
template<typename T> class MyClass;
template<typename T>
T Func(const MyClass<T> &a);
template<typename T>
class MyClass {
// (1) With template type, without namespace: compiles
//friend T Func<T>(const MyClass<T> &a);
// (2) With template type, with namespace: compiles
//friend T ns::Func<T>(const MyClass<T> &a);
// (3) Without template type, without namespace: compiles
//friend T Func<T>(const MyClass &a);
// (4) Without template type, with namespace: doesn't compile
friend T ns::Func<T>(const MyClass &a);
};
}
int main() {
ns::MyClass<int> a;
return 0;
}
My understanding of injected class names is that MyClass
is sufficient to identify MyClass<T>
within the confines of the class itself. However depending on the namespace-qualification of Func
, Visual Studio 2015 fails to compile the friend definition unless MyClass<t>
is used.
Note that this example compiles on at least gcc 5.1. Is this a MSVC bug, or is something else going on here?