3

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 } 

Standard says, that

Finally, looking up a name in the enclosing namespace via explicit qualification (3.4.3.2) will include members of the inline namespace brought in by the using-directive even if there are declarations of that name in the enclosing namespace.

But I can't get it.

2
  • 1
    Neither gcc 4.9 nor clang 3.5 allow this code, you can try on wandbox ... clang 3.4 does though, seems like a bug Commented Dec 2, 2014 at 15:12
  • @ShafikYaghmour Thank you, Shafik. It's wonderful resource. Yes, I tried this code at my job, here I have clang-3.4 Commented Dec 2, 2014 at 15:18

1 Answer 1

5

It looks like this was a pre clang 3.5 bug and there are two defect reports on this 812 and 861. The resolution is in 861 and adds the following to 3.4.3.2 [namespace.qual] (emphasis mine going forward):

For a namespace X and name m, the namespace-qualified lookup set S(X,m) is defined as follows: Let S'(X,m) be the set of all declarations of m in X and the inline namespace set of 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 union of S(Ni,m) for all non-inline namespaces Ni nominated by using-directives in X and its inline namespace set.

and the also relevant additions:

if S(X,m) is the empty set, the program is ill-formed. Otherwise, if S(X,m) has exactly one member, or if the context of the reference is a using-declaration (7.3.3 [namespace.udecl]), S(X,m) is the required set of declarations of m. Otherwise if the use of m is not one that allows a unique declaration to be chosen from S(X,m), the program is ill-formed.

It looks like the change was added pre C++11, this text is present in N3337.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.