16

Consider the following program. Is it well-formed or not according to the c++ standard (references to relevant parts of the standard needed):

namespace X { extern int i; }

namespace N { using X::i; }

int N::i = 1;

int main() {}

I'm getting different results for different compilers. I'm trying to figure out for what compiler I should file a bug report for:

  • Clang: Gives the following compiler error: No member named 'i' in namespace 'N'

  • GCC and Visual C++ compiles it without errors.

For comparison the following gives compiler error with all three compilers:

namespace X { void f(); }

namespace N { using X::f; }

void N::f() {};

int main() {}
9
  • 1
    Funny, VS2013 compiles, but IntelliSence says "Error: namespace "N" has no actual member "i" Commented Jul 18, 2015 at 23:20
  • I think the answer is here: link Commented Jul 18, 2015 at 23:27
  • @Supremum You can get your own copy of the C++ standard to read at isocpp.org/std/the-standard. Commented Jul 18, 2015 at 23:27
  • Jorj Tyron: That link does not answer this question. This question is not about best practices. Commented Jul 18, 2015 at 23:34
  • @Supremum I got it working with CLang by changing "using X::i" to "using namespace X;". Commented Jul 18, 2015 at 23:43

1 Answer 1

11

Current working draft N4527, [8.3p1]:

[...] When the declarator-id is qualified, the declaration shall refer to a previously declared member of the class or namespace to which the qualifier refers (or, in the case of a namespace, of an element of the inline namespace set of that namespace (7.3.1)) or to a specialization thereof; the member shall not merely have been introduced by a using-declaration in the scope of the class or namespace nominated by the nested-name-specifier of the declarator-id. [...]

So, definitely ill-formed; GCC and MSVC are wrong.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.