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]

c++/1925: should issue diagnostic for pure virtual called in dtor



>Number:         1925
>Category:       c++
>Synopsis:       should issue diagnostic for pure virtual called in dtor
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Feb 09 17:36:01 PST 2001
>Closed-Date:
>Last-Modified:
>Originator:     Benoit Hudson
>Release:        2.95.2
>Organization:
>Environment:

>Description:
Consider the code in how-to-repeat.
The call to f() in the destructor has undefined semantics,
because it's a call to a pure virtual whereas we don't
make virtual function calls in the destructor (and 
constructor).

It would be nice to get a better diagnostic than the 
current, a linker error that A::f() isn't defined.
>How-To-Repeat:
#include <stdio.h>
struct A {
    virtual ~A() {
        f();
    }
    virtual void f() = 0;
};

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

int main() {
    B b;
}
>Fix:
Put the dtor call to destroy in the subclass.
>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]