Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | Peter <pilarp@poczta.onet.pl> |
|---|---|
| Newsgroups | comp.std.c++ |
| Subject | Static member of class not found if class name == name of namespace it's defined in |
| Date | 2014-03-12 14:30 -0700 |
| Organization | unknown |
| Message-ID | <0e045ac8-43f6-4456-acfe-96f18ed7bff7@googlegroups.com> (permalink) |
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-submit@vandevoorde.com ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Back to comp.std.c++ | Previous | Next — Next in thread | Find similar
Static member of class not found if class name == name of namespace it's defined in Peter <pilarp@poczta.onet.pl> - 2014-03-12 14:30 -0700 Re: Static member of class not found if class name == name of namespace it's defined in enoquick <enoquick@googlemail.com> - 2014-03-14 12:23 -0600
csiph-web