From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 30746 invoked by alias); 12 Jan 2011 17:17:10 -0000 Received: (qmail 30736 invoked by uid 22791); 12 Jan 2011 17:17:09 -0000 X-SWARE-Spam-Status: No, hits=-2.9 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 12 Jan 2011 17:17:05 +0000 From: "aschepler at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/11750] class scope using-declaration lookup not implemented X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: aschepler at gmail dot com X-Bugzilla-Status: NEW X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 12 Jan 2011 18:24:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2011-01/txt/msg01188.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11750 --- Comment #8 from Andrew Schepler 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.