This snippet compiles in clang,
namespace A {
void f() {
void g();
g();
}
}
void A::g() { }
but GCC only accepts the code if g
is defined inside the namespace A
as follows:
namespace A {
void f() {
void g();
g();
}
void g() {}
}
But I believe there's nothing in [basic.link]/7 disallowing the first snippet above.
[basic.link]/p7, emphasis mine:
When a block scope declaration of an entity with linkage is not found to refer to some other declaration, then that entity is a member of the innermost enclosing namespace. However such a declaration does not introduce the member name in its namespace scope.
[namespace.memdef]/p2, emphasis mine:
Members of a named namespace can also be defined outside that namespace by explicit qualification (3.4.3.2) of the name being defined, provided that the entity being defined was already declared in the namespace and the definition appears after the point of declaration in a namespace that encloses the declaration’s namespace.
GCC is correct. Your first snippet is ill-formed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With