This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/9377: g++ 64bit calls wrong function -> Multi-inheritance: pointer to member function of the 2nd base calss points to wrong place
- From: axiong at ca dot ibm dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 20 Jan 2003 19:35:07 -0000
- Subject: c++/9377: g++ 64bit calls wrong function -> Multi-inheritance: pointer to member function of the 2nd base calss points to wrong place
- Reply-to: axiong at ca dot ibm dot com
>Number: 9377
>Category: c++
>Synopsis: g++ 64bit calls wrong function -> Multi-inheritance: pointer to member function of the 2nd base calss points to wrong place
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Mon Jan 20 19:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator: Guan-Zhu (Andrew) Xiong
>Release: gcc version 3.2
>Organization:
>Environment:
Linux Version 2.4.19:
SuSE SLES 8 (ppc) - Kernel 2.4.19-ul1-ppc64-SMP (34).
>Description:
=> For 64-bit g++ compiling, for the following
Multi-inheritance:
struct B1
struct B2
struct D: B1, B2
pointer to member function of the 2nd base class B2
points to a wrong place. We want to call the function
bar() through a pointer to memebr function of B2, but
another function foo() defined in the drived calss is
called.
=> For the given C++ code, if we compile it with 646-bit
g++ compiler (/opt/cross/bin/powerpc64-linux-g++) and
then run it, we have output:
--------------------
B1::foo() is called
The correct output sould be:
--------------------
D::bar() is called
>How-To-Repeat:
/*********************************************************
* -> compile the code with 64-bit g++ compiler
* - like: powerpc64-linux-g++ -o hello hello.C
* -> run it
* - hello
********************************************************/
#include <stdio.h>
struct B1{
virtual char *foo() { return "B1::foo() is called "; }
};
struct B2{
virtual char * bar() { return "B2::bar() is called "; }
};
struct D : B1, B2 { //change the order of B1 and B2 -> passed
char* foo() { return "D::foo() is called "; }
char* bar() { return "D::bar() is called "; }
};
typedef char * (D::*PMF)();
PMF select() { return 0; } //put this function here to avoid memory fault
main() {
D *d1ptr = new D ;
PMF aPMF = (char *(D::*)()) &B2::bar ;
printf( "%s\n", (d1ptr->*aPMF)() ) ;
return 0 ;
}
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: