C++ nested template issue
From [temp.mem.class/1], we have
A member class of a class template may be defined outside the class template definition in which it is declared.
Furthermore, in a non-template context, [class.nest/2] tells us:
Member functions and static data members of a nested class can be defined in a namespace scope enclosing the definition of their class.
Let's hence construct a simpler example and verify that the definition of a member function of a nested type is allowed to be separated from the definition of the nested, non-template type itself. In analogy to the types in your snippet:
template <class FOO>
struct Foo {
// Simpler, Bar is not a template
struct Bar;
};
// Definition of Bar outside of Foo as before
template <class FOO>
struct Foo<FOO>::Bar {
static void test();
};
And now the critical part, the definition of Bar::test()
outside of Bar
itself:
template <class FOO>
void Foo<FOO>::Bar::test() { }
This happily compiles with both gcc-8
and clang
(trunk as well as a much older stable version).
I might be misunderstanding something here, but my conclusion is that the syntax to define Foo::Bar::test()
outside of Foo
and outside of Bar
is indeed fine, and clang
should compile it as gcc
does.