for the following test case:
struct A {
  virtual int x () {return 1;}
};

struct B: A {
  virtual int x () {return 0;}
};

struct C: B{
   using A::x;
};

int main()
{
  C c;
  return c.x();
}

all g++ 4.x will return 1
It seems C++ standard would want to see 0.
Using-declaration introduces the virtual method x() in the class C and
it's supposed to stay 'virtual', whereas g++ seems to treat it as it overrides
the B's method. In other words using-declaration should effectively be
ignored in this case.

quote from the standard:
"
 The rules for member lookup (10.2) are used to determine the final
 overrider for a virtual function in the scope of a derived class but ignoring
names introduced by using-declarations.
[ Example:
 struct A {
   virtual void f();
 };
 struct B : virtual A {
   virtual void f();
 };
 struct C : B , virtual A {
   using A::f;
 };
 void foo () {
   C c;
   c.f ();    // calls B::f, the final overrider
   c.C::f (); // calls A::f because of the using-declaration
 }
—end example ]
"


-- 
           Summary: incorrect semantics of using-declaration in c++
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: alexey dot starovoytov at sun dot com
 GCC build triplet: all
  GCC host triplet: all
GCC target triplet: all


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=28748

Reply via email to