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] New: Ambiguous code gets compiled successfully when class and its namespace have the same name


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

            Bug ID: 68188
           Summary: Ambiguous code gets compiled successfully when class
                    and its namespace have the same name
           Product: gcc
           Version: 5.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppilar11 at gmail dot com
  Target Milestone: ---

I reported this nearly 2 years ago (#60025), but my bug report was completely
ignored and the problem still persists.

Consider the following code:

namespace Foo
{
    int x;

    class Foo
    {
        public:
        static int x;
    };

    int Foo::x;
}

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

g++ 5.2.0 accepts it even though Foo::x is ambiguous: it could be either a
global variable in namespace Foo or a static member of class Foo. Visual C++
2013 rejects the code with "error C2872: 'Foo' : ambiguous symbol could be
'Foo' or 'Foo::Foo'" while g++ simply resolves Foo::x to the global variable x,
so it apparently fails to find the static member of class Foo. The problem has
been present since at least g++ 4.7.2.

Maybe I'm wrong, but I think there's one more problem with the above code.
If I comment out the global variable x from namespace definition then 
compilation fails with the following error:

"error: 'x' is not a member of 'Foo'"

so g++ fails to find the static member of class Foo unless I qualify it as
Foo::Foo::x which should not be necessary due to "using" directive, am I right?

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