$ cat >test.cxx namespace n { namespace m { } } using n::m; $ g++ --version g++ (GCC) 3.4.0 $ g++ -c test.cxx test.cxx:8: error: namespace `n::m' not allowed in using-declaration I have searched through the standard and did not find any restrictions on the type of name in using-declaration.
There is a defect report about this at: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460
Confirmed.
Can somebody please enlighten me about what's wrong with using-declaration naming a namespace?
Possibly nothing, though it seems (from the DR) as if the makers of the standard intended the using declaration for names of classes, functions, variables, etc. For namespaces why not use the using directive using namespace namespace-name; which seems to be the more obvious choice anyway? Given that the DR lists that this should be an error, it seems unlikely that this 'bug' will be fixed in the direction which you seem to prefer. W.
> For namespaces why not use the using directive Because it is not the same. > Given that the DR lists that this should be an error It does not. It is still in drafting state. I guess I will have to ask at comp.std.c++
I'm not sure what you want. Of course the DR is only in drafting stage, but an inclination has been expressed, and the gcc project would be ill-advised to implement anything now that would oppose this inclination. As for your question of why a using-declaration should not be allowed to name namespace names: using declarations are used to inject declarations into a scope, for example into a class scope: class Base { void f(int); }; class Derived : public Base { using Base::f; void f(double); }; Obviously, allowing a namespace name in a using-declaration inside a class declaration does not make much sense. I think I'm just confused what effect you try to achieve by allowing namespace names in using-declarations that can't be achieved by other means as well? W.
Subject: Re: [DR460] using-declaration of namespace name bangerth at dealii dot org > > ------- Additional Comments From bangerth at dealii dot org 2004-07-12 > 18:52 ------- > Possibly nothing, though it seems (from the DR) as if the makers > of the standard intended the using declaration for names of classes, > functions, variables, etc. For namespaces why not use the using > directive > using namespace namespace-name; > which seems to be the more obvious choice anyway? because (1) it is arbitrary restriction (2) it has a *very* very different meaning. It modifies name lookup -- the original poster did NOT intend to dump everything in the current scope. I'm amazed at seeing the proposed resolution. I suppose I have to raise that at the next meeting. -- Gaby
> Obviously, allowing a namespace name in a using-declaration inside a class > declaration does not make much sense. This is a bogus argument! Only names from base are allowed in using-declaration inside a class. Following your logic we should also ban somethin like namespace n { class foo {}; }; using n::foo; Just because you cannot write class bar { using n::foo; }; > I think I'm just confused what effect you try to achieve by allowing namespace > names in using-declarations that can't be achieved by other means as well? Sure it can be achived by other means. I just don't see a reason why should it be achived by other means? Here is the whole story: I have some amount of code which works fine with gcc 3.x.y. Now I try to compile it with gcc 3.4.x and it gives me an error about using-declaring namespace. Ok, I am thinking to myself, it is probably either illegal or bug in gcc. So I am searching throug the standard for any restrictions on the type of name that can be used in using-declaration. The standard say none. Ok, I am thinking to myself, there doesn't seem to be any good reason why one shouldn't using-declare a namespace so it must be a bug in gcc. I am posting a bug report which is closed due to a defect report (which, btw, hasn't been even voted upon) that says "we believe it should be an error". Don't take it personaly, but if there is a defect report that says everybody should start jumping off the roof, would you? I posted a question to std.c++. I will follow up if anything comes out.
Subject: Re: [DR460] using-declaration of namespace name bangerth at dealii dot org: > As for your question of why a using-declaration should not be allowed to > name namespace names: using declarations are used to inject declarations > into a scope, for example into a class scope: Right. > class Base { > void f(int); > }; > class Derived : public Base { > using Base::f; > void f(double); > }; > Obviously, allowing a namespace name in a using-declaration inside a class > declaration does not make much sense. Why doesn't it make sense? A definition is a declaration, so if the namespace has an original-definition, it makes all sense to bring its name into current scope. I think I'm just confused what > effect > you try to achieve by allowing namespace names in using-declarations that > can't be achieved by other means as well? I'm confused as to why people would like to ban using-declaration for namespace-names. -- Gaby
Subject: Re: [DR460] using-declaration of namespace name boris at kolpackov dot net: > Sure it can be achived by other means. I just don't see a reason why > should it > be achived by other means? I'm of the opinion that it is a mistake to ban using-declarations that bring namespace names into scope. I'll take it to Core. -- Gaby
> I'm of the opinion that it is a mistake to ban using-declarations > that bring namespace names into scope. I'll take it to Core. Thanks Gaby.
In response to comment #8: Boris, you will have realized that I was the one who actually _reopened_ the bug. I may have been misunderstood, my statement was rather meant to say that I believe that nothing will happen with this PR until the DR has been formally voted on. gcc does try to implement voted on DRs, and sometimes DRs for which the outcome seems predictable. However, I don't see anyone going to implement your suggestion as long as the audit trail of the PR indicates that the committee might decide in the opposite direction. If the committee changes its mind, then that's a completely different matter. As for my questions why one would want to ban this: I was merely giving a few hints. I am not a member of the committee, so I have no idea what they were thinking. My opinion is unimportant in that matter. If I have stepped on someone's feet, I apologize. My intent was certainly not to start a flame war. W.
Note actually this bug never got closed at all. I read the DR report and confirmed it, I was thinking about suspending it but decided against that because the DR was already in drafting which means they were drafting the final conclusion to the DR.
Hmm, it looks like GCC is going to be correct and rejecting this. The DR is now in ready state (I forgot what this means).
The resolution of DR460 makes this code illegal and GCC's behaviour correct.
Closing as invalid based on the resolution of the Defect report making this code invalid and should be rejected as GCC does.