I accidentally discovered that g ++ (5.2.0) compiles the following
template<typename T>
struct A {
int x;
struct B {
void foo() {
x = 1;
}
};
};
even istantition A
and A::B
if the item is B::foo
not used. You reasonably get instead a compilation error for x
, which is a non-static member A
, even just by compiling the no-op operator &A<int>::B::foo;
.
clang (3.6.2), however, discards the template, even if A
it is not created at all, because it says that the name of the non-static member x
cannot be used internally B
by simply reading the template definition.
Is this a bug in g ++ or clang too strict for template members that are not created?