This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
c++/2577: pure virtual destructors must not be called ?
- To: gcc-gnats at gcc dot gnu dot org
- Subject: c++/2577: pure virtual destructors must not be called ?
- From: moyere at objectif dot fr
- Date: 18 Apr 2001 10:35:45 -0000
- Reply-To: moyere at objectif dot fr
>Number: 2577
>Category: c++
>Synopsis: pure virtual destructors must not be called ?
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Wed Apr 18 03:36:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator: moyere@objectif.fr
>Release: gcc version egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)
>Organization:
>Environment:
RedHat Linux 6.2 on i586
>Description:
With inheritance, a destructor must call the destructor of
its parents.
In the following example, the class A (the parent) has a pure virtual destructor. This destructor must not be called
when the destructor of the B class (the child class) is called.
The generated code is wrong and the linker looks for a destructor that doesn't exist.
A solution is to give an empty implementation to the A destructor (ie write : virtual ~A() {} instead of virtual ~A() = 0;).
class A {
public:
virtual ~A() = 0;
virtual void method(void) = 0;
};
class B : public A {
public:
virtual ~B() {};
void method(void) {};
};
int main(int argc, char **argv) {
B b;
b.method();
}
This gives the following error:
gcc -g3 t.cc -o t
/tmp/ccKjy7Ar.o: In function `A type_info function':
t.cc:21: undefined reference to `A::~A(void)'
t.cc:21: undefined reference to `A::~A(void)'
collect2: ld returned 1 exit status
>How-To-Repeat:
>Fix:
>Release-Note:
>Audit-Trail:
>Unformatted: