This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

c++/9485: g++ 3.4: wrong class's virtual function called


>Number:         9485
>Category:       c++
>Synopsis:       g++ 3.4: wrong class's virtual function called
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Jan 28 18:46:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     scott snyder
>Release:        3.4 20030127 (experimental)
>Organization:
<organization of PR author (multiple lines)>
>Environment:
System: Linux karma 2.4.19-emp_2419p5a829i #1 Tue Sep 3 17:42:17 EST 2002 i686 unknown
Architecture: i686

	<machine, os, target, libraries (multiple lines)>
host: i686-pc-linux-gnu
build: i686-pc-linux-gnu
target: i686-pc-linux-gnu
configured with: ../gcc/configure --prefix=/usr/local/gcc --enable-threads=posix --enable-long-long
>Description:

This bug is perhaps related to the earlier c++/9415 that i reported; however,
the fix for that one does not fix this case.

In the function foofoo() in the test case below, the construction

B* type;
type -> A::construct ();

does not call A::construct as intended; rather, it calls B::construct,
as can be seen by running the program:

$ g++ -o x x.cc
$ ./x
B
$


>How-To-Repeat:

-------------------------
extern "C" int printf (...);

struct A
{
  virtual void construct () { printf ("A\n"); }
};

struct B : public A
{
  virtual void construct () { printf ("B\n"); }
};

void foofoo (B* type)
{
  type -> A::construct ();
}

int main ()
{
  foofoo (new B);
  return 0;
}
-------------------------

>Fix:
	<how to correct or work around the problem, if known (multiple lines)>
>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]