Google Groups จะไม่รองรับโพสต์หรือการสมัครสมาชิก Usenet ใหม่อีกต่อไป โดยคุณจะยังคงดูเนื้อหาเดิมได้อยู่

fixed: virtual table redirection bug

ยอดดู 0 ครั้ง
ข้ามไปที่ข้อความที่ยังไม่อ่านรายการแรก

Gordon Hogenson

ยังไม่อ่าน,
11 ก.ย. 2538 03:00:0011/9/38
ถึง
Ray,

Thanks for the bug report of 20 May 93. This bug was fixed
sometime between versions 2.5.8 and 2.7.0 of g++. When run,
I get:

t13% a.out
B construct
C construct
255c
253c
BC extract
BC update
B destroy
---------
B construct
C construct
255c
253c
BC extract
BC update
B destroy
t13%

on a Sun/SunOS 4.1.4. (In future please specify the machine and OS when
you submit a bug report.)

Gordon.
--------------------------------------------------------------
Date: Thu, 20 May 1993 12:27:10 -0400
From: r...@klg.com (Raymon Singh)
Sender: gnul...@ai.mit.edu
Message-Id: <930520162...@klg.com>
To: bug...@prep.ai.mit.edu
Subject: virtual table redirection bug
Resent-From: bug-gcc...@prep.ai.mit.edu
Status: RO

There seems to be a bug in the following code when compiled with gcc
ver 2.2.2 and 2.3.3.

#include <stdio.h>

class C {
public:
C() {puts("C construct");}
virtual void extract() {puts("C extract");}
virtual void update() {puts("C update");}
};

class B {
public:
B() {puts("B construct");}
virtual ~B() {puts("B destroy");}
virtual void extract() {puts("B extract");}
virtual void update() {puts("B update");}
};

class BC : public B, public C {
public:
void extract() {puts("BC extract");};
void update() {puts("BC update");};
};


void boo1()
{
BC foo;

printf("%lx\n", (foo.extract));
printf("%lx\n", (foo.update));
foo.extract();
foo.update();
}

void boo2()
{
BC *foo = new BC;

printf("%lx\n", (foo->extract));
printf("%lx\n", (foo->update));
foo->extract();
foo->update();

delete foo;
}

main()
{
boo1();
puts("---------");
boo2();
}

I compiled this without any options and got the following output:

> a.out
B construct
C construct
2454
2484
BC extract
BC update
B destroy
---------
B construct
C construct
2314
1
C update
Bus error (core dumped)
>

foo.extract() works fine but foo->extract() does not. I tracked it
down in gdb and it seems to be an off by one error. Instead of
referencing the given function it gives the next element in the
virtual table.

I've compiled this with 5 other C++ compilers and they work ok. Is
there a compiler option that I need to set? I've tried
-felide-constructors but that didn't make a difference. If you make
~B a non-virtual function then the problem goes away but I suspect
that is not the real problem.

Any help would be greatly appreciated.


---------------------------------------------------------------
Gordon J. Hogenson work: (505) 667-9471
ghog...@u.washington.edu home: (505) 661-6753
---------------------------------------------------------------


ข้อความใหม่ 0 รายการ