Thread View: gnu.g++.help
2 messages
2 total messages
Started by Lee Cooprider
Sun, 13 Sep 1992 23:08
Problem with virtual destructors
Author: Lee Cooprider
Date: Sun, 13 Sep 1992 23:08
Date: Sun, 13 Sep 1992 23:08
45 lines
1502 bytes
1502 bytes
I am using C++ from gcc version 2.2.1 on a Sparc platform.
My problem is with virtual destructors. Whenever my real destructor is
called, the program abort()'s after executing the destructor successfully.
This program illustrates the problem:
class aaa {
public:
virtual ~aaa() = 0;};
class bbb : public aaa {
public:
bbb();
~bbb();};
bbb::bbb() {}
bbb::~bbb() {}
The assembler for ~bbb() has an unconditional abort() call at the end. Is
this the correct code? Is there an additional requirement on virtual
destructors? Is it not legal for a destructor to be pure-virtual?
This is the assembler code for the ~bbb() routine above:
__$_3bbb:
!#PROLOGUE# 0
save %sp,-112,%sp
!#PROLOGUE# 1
mov %i0,%l0
st %i1,[%fp+72]
sethi %hi(__vt$bbb),%o1
or %o1,%lo(__vt$bbb),%o0
st %o0,[%l0]
L4:
mov %l0,%o0
ld [%fp+72],%o1
call _abort,0
nop
L3:
ret
restore
--
Lee W. Cooprider PP-ASEL/IA
Lee_Cooprider@vos.stratus.com Skylane N2908F "Wiley"
Re: Problem with virtual destructors
Author: Peter C. McCluskey
Date: Tue, 15 Sep 1992 19:55
Date: Tue, 15 Sep 1992 19:55
35 lines
1877 bytes
1877 bytes
In article <6334@transfer.stratus.com>, lee@bluefuzz.sw.stratus.com (Lee Cooprider) writes:
|> I am using C++ from gcc version 2.2.1 on a Sparc platform.
|>
|> My problem is with virtual destructors. Whenever my real destructor is
|> called, the program abort()'s after executing the destructor successfully.
|>
|> This program illustrates the problem:
|>
|> class aaa {
|> public:
|> virtual ~aaa() = 0;};
|>
|> class bbb : public aaa {
|> public:
|> bbb();
|> ~bbb();};
|>
|> bbb::bbb() {}
|> bbb::~bbb() {}
|>
|> The assembler for ~bbb() has an unconditional abort() call at the end. Is
|> this the correct code? Is there an additional requirement on virtual
|> destructors? Is it not legal for a destructor to be pure-virtual?
This is a bug in g++. The way cfront works (which is apparently the correct
way, although I haven't found a convincing explanation of why) is that a
definition of aaa::~aaa(){} is needed even though it is pure, because derived
class destructors always produce an implicit call to their base class destructors.
cfront gives a warning during compilation saying that the definition must be
provided.
----------------------------------------------------------------------
\\ !Vote Libertarian! \\ Peter McCluskey \\ !Vote Libertarian! \\
// Vote Marrou in `92 // pcm@cs.brown.edu // Vote Marrou in `92 //
----------------------------------------------------------------------
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads