http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11750
--- Comment #8 from Andrew Schepler <aschepler at gmail dot com> 2011-01-12 17:16:29 UTC --- (In reply to comment #6) > > struct A { > > virtual void f(); > > }; > > struct B : virtual A { > > virtual void f(); > > }; > > > > struct C : B , virtual A { > > using A::f; > > }; > Im using g++ 4.4.5 > With the same example with my main function as below, > int main() > { > C c; > c.f() // Calls A::f > C* pc = &c; > pc->f() // Calls B::f > } > > With the same object when accessed directly produces different results and > when > accessed using a pointer of same type produces a different result. Even if gcc > violates standard, there has to be some proper explanation. The reason is that when f is invoked via a pointer or reference, g++ uses the vtable lookup to call the correct final override. But when the object in the member access is not a pointer or reference (it is a non-reference identifier as here, or qualified id, or class member), g++ can usually optimize away the virtual call and just call the correct member function. In this case the logic for calling the correct member function for that optimization is incorrect, but virtual calls still work correctly.