From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22700 invoked by alias); 12 Jan 2011 16:57:31 -0000 Received: (qmail 22690 invoked by uid 22791); 12 Jan 2011 16:57:29 -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 16:57:23 +0000 From: "balakrishnan.erode 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: balakrishnan.erode 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: CC 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 17:06: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/msg01184.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11750 Balakrishnan B changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |balakrishnan.erode at gmail | |dot com --- Comment #6 from Balakrishnan B 2011-01-12 16:57:07 UTC --- (In reply to comment #0) > Paragraph 10.3/2 in the C++ standard [ISO/IEC 14882:1998] provides the > following > code 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 > } > > > > When a similar program is compiled using G++ 3.3, the method call 'c.f()' in > function foo() incorrectly invokes A::f and not B::f as specified in the > standard. > > > > #include > > struct A { > virtual void f() { std::cout << "A::f()\n"; } > }; > struct B : virtual A { > virtual void f() { std::cout << "B::f()\n"; } > }; > struct C : B, virtual A { > using A::f; > }; > > int main() > { > C c; > c.f(); // ERROR - Incorrectly invokes A::f > c.C::f(); // OK - Invokes A::f > } > > > > $ g++ main.cpp > > $ ldd a.out > libstdc++.so.5 => > /usr/local/gcc/3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/libstdc++.so.5 > (0x40017000) > libm.so.6 => /lib/tls/libm.so.6 (0x400e4000) > libgcc_s.so.1 => > /usr/local/gcc/3.3/lib/gcc-lib/i686-pc-linux-gnu/3.3/libgcc_s.so.1 (0x40106000) > libc.so.6 => /lib/tls/libc.so.6 (0x42000000) > /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000) > > > > $ ./a.out > A::f() > 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.