From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14158 invoked by alias); 19 Mar 2002 18:06:12 -0000 Mailing-List: contact gcc-prs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-prs-owner@gcc.gnu.org Received: (qmail 14069 invoked by uid 71); 19 Mar 2002 18:06:03 -0000 Resent-Date: 19 Mar 2002 18:06:03 -0000 Resent-Message-ID: <20020319180603.14068.qmail@sources.redhat.com> Resent-From: gcc-gnats@gcc.gnu.org (GNATS Filer) Resent-To: nobody@gcc.gnu.org Resent-Cc: gcc-prs@gcc.gnu.org, gcc-bugs@gcc.gnu.org Resent-Reply-To: gcc-gnats@gcc.gnu.org, jody@ifi.unizh.ch Received:(qmail 8363 invoked by uid 61); 19 Mar 2002 17:58:36 -0000 Message-Id:<20020319175836.8358.qmail@sources.redhat.com> Date: Tue, 19 Mar 2002 10:06:00 -0000 From: jody@ifi.unizh.ch Reply-To: jody@ifi.unizh.ch To: gcc-gnats@gcc.gnu.org X-Send-Pr-Version:gnatsweb-2.9.3 (1.1.1.1.2.31) Subject: c++/6006: problem with pure virtual functions and destructord X-SW-Source: 2002-03/txt/msg00725.txt.bz2 List-Id: >Number: 6006 >Category: c++ >Synopsis: problem with pure virtual functions and destructord >Confidential: no >Severity: non-critical >Priority: medium >Responsible: unassigned >State: open >Class: sw-bug >Submitter-Id: net >Arrival-Date: Tue Mar 19 10:06:00 PST 2002 >Closed-Date: >Last-Modified: >Originator: jody weissmann >Release: gcc version 2.95.2 19991024 (release) >Organization: >Environment: sparc-sun-solaris2.8 >Description: A pure virtual method f() of a class A CANNOT be called from within the destructor ~A of the class A. However, it can be called from within a normal method g() of A. But strangely enough, g() can be called from within the destructor ~A of A. The error message created when f9) is called from within ~A: Undefined first referenced symbol in file A::f(void) BugProg.o ld: fatal: Symbol referencing errors. No output written to BugProg collect2: ld returned 1 exit status >How-To-Repeat: The error appears when the program below is compiled: g++ -o BugProg BugProg.cpp Here comes the source of BugProg.cpp //------------------------------------- // BugProg.cpp // //------------------------------------- //------------------------------------- // declaration of A // class A { public: A(void); ~A(void); virtual void f(void)=0; void g(void); }; //------------------------------------- // implementation of B // class B : public A { public: B(void); virtual void f(void); }; //------------------------------------- // implementation of A // A::A(void) { } A::~A(void) { f(); // this doesn't work g(); // but this works } void A::g(void) { f(); } //------------------------------------- // implementation of B // B::B(void) : A() { } void B::f(void) { } //------------------------------------- // main // void main(void) { B *pB = new B(); delete pB; } >Fix: Workaround: if a normal method g() of A calls the pure virtual method f() of A, then g() can be called from within the destructor >Release-Note: >Audit-Trail: >Unformatted: ----gnatsweb-attachment---- Content-Type: application/octet-stream; name="BugProg.ii" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="BugProg.ii" IyAxICJCdWdQcm9nLmNwcCIKIAogCiAKY2xhc3MgQSB7CnB1YmxpYzoKICBBKHZvaWQpOwogfkEo dm9pZCk7CiAKICB2aXJ0dWFsIHZvaWQgZih2b2lkKT0wOwogIHZvaWQgZyh2b2lkKTsKfTsKCgog CiAKIApjbGFzcyBCIDogcHVibGljIEEgewpwdWJsaWM6CiAgQih2b2lkKTsKIAogIHZpcnR1YWwg dm9pZCBmKHZvaWQpOwp9OwoKCiAKIAogCkE6OkEodm9pZCkgewp9CgpBOjp+QSh2b2lkKSB7CiAg ZigpOyAgICAgCiAgZygpOyAgICAgIAp9Cgp2b2lkIEE6Omcodm9pZCkgewogIGYoKTsKfSAgCgoK IAogCiAKQjo6Qih2b2lkKSAKICA6IEEoKSB7Cn0KCnZvaWQgQjo6Zih2b2lkKSB7Cn0KCgogCiAK IAp2b2lkIG1haW4odm9pZCkgewogIEIgKnBCID0gbmV3IEIoKTsKICBkZWxldGUgcEI7Cn0K