Bug 16468 - [DR460] using-declaration of namespace name
Summary: [DR460] using-declaration of namespace name
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2004-07-10 21:04 UTC by Boris Kolpackov
Modified: 2005-12-07 04:34 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-05-01 03:16:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Boris Kolpackov 2004-07-10 21:04:06 UTC
$ 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.
Comment 1 Kriang Lerdsuwanakij 2004-07-11 14:51:01 UTC
There is a defect report about this at:

  http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#460

Comment 2 Andrew Pinski 2004-07-12 06:38:58 UTC
Confirmed.
Comment 3 Boris Kolpackov 2004-07-12 15:54:45 UTC
Can somebody please enlighten me about what's wrong with using-declaration
naming a namespace?
Comment 4 Wolfgang Bangerth 2004-07-12 18:52:04 UTC
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. 
Comment 5 Boris Kolpackov 2004-07-12 18:58:41 UTC
> 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++
Comment 6 Wolfgang Bangerth 2004-07-12 20:53:50 UTC
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. 
Comment 7 Gabriel Dos Reis 2004-07-12 21:24:58 UTC
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

Comment 8 Boris Kolpackov 2004-07-12 21:25:37 UTC
> 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.
Comment 9 Gabriel Dos Reis 2004-07-12 21:27:27 UTC
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

Comment 10 Gabriel Dos Reis 2004-07-12 21:32:23 UTC
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

Comment 11 Boris Kolpackov 2004-07-12 21:38:01 UTC
> 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.
Comment 12 Wolfgang Bangerth 2004-07-13 04:18:48 UTC
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. 
Comment 13 Andrew Pinski 2004-07-13 04:25:22 UTC
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.
Comment 14 Andrew Pinski 2005-05-01 03:16:13 UTC
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).
Comment 15 Jonathan Wakely 2005-08-31 21:10:25 UTC
The resolution of DR460 makes this code illegal and GCC's behaviour correct.
Comment 16 Andrew Pinski 2005-12-07 04:34:43 UTC
Closing as invalid based on the resolution of the Defect report making this code invalid and should be rejected as GCC does.