This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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)?

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]