I have defined a class Bar inside a member function (constructor) Foo, that I am trying to use as a template parameter.
template<typename Ty>
struct Spam {
template<class U, class D> Spam(U*, D) {}
};
struct Foo {
Foo() {
struct Bar {};
int *ptr = NULL;
Spam<int> pSpam(ptr, Bar());
}
};
My guess is that the usage is invalid as the scope of Bar is local to Foo and cannot have a global visibility which is required for template instantiation. But on a second though, I am instantiating the template in the same scope of Bar, and though the template class/struct is global, there should not be any accessibility issues of the template instance.
I tried across multiple compilers, and each behaves differently. Particularly
clang accepted with warning
warning: template argument uses local type 'Bar' [-Wlocal-type-template-args]
VC++ compiled without warning
GCC 4.3.4 compilation failed
10 : error: no matching function for call to 'Spam::Spam(int*&, Foo::Foo()::Bar)' 3 : note: candidates are: Spam::Spam(const Spam&)
GCC C++14 compiled successfully
What is the expected behaviour according to the standards?