Some time ago I started a topic on comp.lang.c++
about possible bug in g++ found by me. Although there was
no general agreement as to whether it's a compiler bug or language
underspecification, there was a conclusion that something was
definitely wrong with my code example since g++ and Visual C++
handled it differently. I also sent a bug report to g++ bugzilla
more than a month ago, but no one seemed to care
as I receved no reply and bug status hasn't changed.
Consider this definition:
namespace Foo
{
int x;
class Foo
{
public:
static int x;
};
int Foo::x;
}
and test code in which it's used:
int main()
{
using namespace Foo;
Foo::x;
return 0;
}
Both g++ 4.7.2 and g++ 4.8.1 accept the above code even
though Foo::x is ambiguous: could be either a global variable
in namespace Foo or static member of class Foo. Visual C++ 2013
rejects the code with "error C2872: 'Foo' : ambiguous symbol could
be 'Foo' or 'Foo::Foo'", g++ simply resolves Foo::x to global
variable x.
If I comment out the global variable x from namespace definition
then both g++ 4.7.2 and g++ 4.8.1 reject the code with
"error: 'x' is not a member of 'Foo'", so they fail 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).
What's your opinion? Personally I think Visual C++ is right
here. Since this is a group focused on C++ standard
compliance you can probably decide what's the correct way
a compiler should handle my example.
--
[ comp.std.c++ is moderated. To submit articles, try posting with your ]
[ newsreader. If that fails, use mailto:
std-cpp...@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ:
http://www.comeaucomputing.com/csc/faq.html ]