From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 29715 invoked by alias); 12 Jul 2006 20:29:42 -0000 Received: (qmail 29707 invoked by uid 22791); 12 Jul 2006 20:29:41 -0000 X-Spam-Check-By: sourceware.org Received: from ntpop.eye.ch (HELO ntpop.eye.ch) (194.209.79.150) by sourceware.org (qpsmtpd/0.31) with ESMTP; Wed, 12 Jul 2006 20:29:39 +0000 Received: from [192.168.0.2] [84.74.130.113] by ntpop.eye.ch with ESMTP (SMTPD32-8.05) id ABB0799E00C6; Wed, 12 Jul 2006 22:29:36 +0200 Message-ID: <44B55CBA.5040500@gmail.com> Date: Wed, 12 Jul 2006 20:29:00 -0000 From: "michid@gmail.com" User-Agent: Thunderbird 1.5.0.4 (Windows/20060516) MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Wrong virtual method called (bug?) Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org X-SW-Source: 2006-07/txt/msg00152.txt.bz2 The following program gives different output on g++ 3.3.6 and 4.0.3. With 3.3.6 it prints D::foo() D::foo() with 4.0.3 it prints C::foo() D::foo() which is what I'd expected it to print. Is this a known issue? Michael #include using namespace std; struct B { virtual void foo() const = 0; }; struct C: B { virtual void foo() const { cout << "C::foo()" << endl; } }; struct D: B { virtual void foo() const { cout << "D::foo()" << endl; } }; struct A { const B &b; A(const B& x = C()): b(x) {} void foo() { b.foo(); } }; int main() { A a1 = A(C()); A a2 = A(D()); a1.foo(); a2.foo(); return 0; }