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() {}
Supremum
  • 542
  • 7
  • 23
  • 1
    Funny, VS2013 compiles, but IntelliSence says `"Error: namespace "N" has no actual member "i"` – AlexD Jul 18 '15 at 23:20
  • I think the answer is here: [link](http://stackoverflow.com/questions/6175705/scope-of-using-declaration-within-a-namespace) – Jorj Jul 18 '15 at 23:27
  • @Supremum You can get your own copy of the C++ standard to read at https://isocpp.org/std/the-standard. – Coder Jul 18 '15 at 23:27
  • Jorj Tyron: That link does not answer this question. This question is not about best practices. – Supremum Jul 18 '15 at 23:34
  • @Supremum I got it working with CLang by changing "using X::i" to "using namespace X;". – Coder Jul 18 '15 at 23:43
  • VS2013 compiles but in editor says *Error: namespace "N" has no actual member "i"* ! Same for you @AlexD? What VS2013 version do you have? – Jorj Jul 19 '15 at 00:08
  • @JorjTyron `VS Professional 2013, Version 12.0.21005.1 REL` – AlexD Jul 19 '15 at 00:08
  • @Supremum Have you reported this for MSVC, by any chance? – bogdan Aug 01 '15 at 18:19
  • @bogdan: I have reported 12 bugs to clang 15 bugs to gcc (not counting some rejected ones). If you search for Anders Granlund as reporter in the bugzilla pages for clang and gcc you will find them. Some of them, like this one exists in MSVC also, but I have not made any reports to MSVC. Feel free to do that if you want to. – Supremum Aug 04 '15 at 11:20

1 Answers1

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.

bogdan
  • 9,229
  • 2
  • 33
  • 48