Internal namespaces and ambiguous declarations
I'm wondering if this is allowed:
namespace A {
inline namespace B {
int a;
}
int a;
}
void foo() {
A::a = 0; // clang 3.4 compiles, but gcc doesn't
}
The standard says that
Finally, searching for a name in the enclosing namespace using explicit qualification (3.4.3.2) will include members of the inline namespace injected using the use directive, even if there is a statement of that name in the enclosing namespace.
But I can't figure it out.
source to share
It looks like it was a pre clang 3.5 bug and there are two bug reports on this 812 and 861 . The resolution is at 861 and adds the following to 3.4.3.2
[namespace.qual] (highlighting mine in front):
For a namespace X and a name m, the defining namespace set S (X, m) is defined as follows: let S '(X, m) be the set of all m declarations in X and the built-in namespace set from X (7.3.1 [namespace. def]). If S '(X, m) is not empty, S (X, m) is S' (X, m); otherwise S (X, m) is the concatenation of S (Ni, m) for all non-string Ni namespaces assigned by directives in X and its inline namespace.
as well as related additions:
if S (X, m) is an empty set, the program is poorly formed. Otherwise, if S (X, m) has exactly one member, or if the link context is declaration-use (7.3.3 [namespace.udecl]), S (X, m) is the required set of m declarations. Otherwise, if the use of m is not one that allows you to select a unique declaration from S (X, m), the program is ill-formed.
It looks like the change was added before C ++ 11, this text is present in N3337 .
source to share