Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.std.c++ > #713

Re: Static member of class not found if class name == name of namespace it's defined in

Message-ID <lfsebg$fho$1@dont-email.me> (permalink)
Newsgroups comp.std.c++
From enoquick <enoquick@googlemail.com>
Subject Re: Static member of class not found if class name == name of namespace it's defined in
Organization A noiseless patient Spider
References <0e045ac8-43f6-4456-acfe-96f18ed7bff7@googlegroups.com>
Date 2014-03-14 12:23 -0600

Show all headers | View raw


Il 12/03/2014 15:30, Peter ha scritto:
>
> 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.
>
>

It' a g++ bug
In this case Foo::x is ambiguos


to be in theme another bug is (g++ 4.6.3):


<CODE>


class A {
public:
        class B {};
};

bool operator ==(const A::B&,const A::B&) { return true; }


template <typename T>
class C {
public:
        class D {};
};

template <typename T>
bool operator==(const typename C<T>::D&,const typename C<T>::D&) {
return true; }


int main()
{
        A::B() == A::B(); // OK
        C<int>::D() == C<int>::D(); // error
}


</CODE>


I don't now the behavior of VC++ or the next release of g++





--
[ 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 | NextPrevious in thread | Find similar


Thread

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