[Bug c++/68188] Ambiguous code gets compiled successfully when class and its namespace have the same name

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Nov 3 10:37:00 GMT 2015


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68188

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid,
                   |                            |rejects-valid

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
So the actual bug is that the following is rejected:

namespace Foo
{
  class Foo
    {
    public:
      static int x;
    };

  int Foo::x;
}

int main()
{
  using namespace Foo;
  Foo::x;
  return 0;
}

which means that GCC does not consider the used namespace Foo when seeing
the qualified name 'Foo::x' (it finds Foo::Foo:x just fine).

When changing the above to

namespace Foo
{
  namespace Foo
    {
      int x;
    }
}
int main()
{
  using namespace Foo;
  Foo::x;
  return 0;
}

then we get

t.C: In function ‘int main()’:
t.C:11:3: error: reference to ‘Foo’ is ambiguous
   Foo::x;
   ^
t.C:2:1: note: candidates are: namespace Foo { }
 {
 ^
t.C:4:5: note:                 namespace Foo::Foo { }
     {
     ^

which means that the actual ambiguity is on 'Foo' (also with your own
testcase)?


More information about the Gcc-bugs mailing list