public inbox for gcc-prs@sourceware.org
help / color / mirror / Atom feed
From: jody@ifi.unizh.ch
To: gcc-gnats@gcc.gnu.org
Subject: c++/6006: problem with pure virtual functions and destructord
Date: Tue, 19 Mar 2002 10:06:00 -0000	[thread overview]
Message-ID: <20020319175836.8358.qmail@sources.redhat.com> (raw)


>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


             reply	other threads:[~2002-03-19 18:06 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-19 10:06 jody [this message]
2002-05-14  8:46 lerdsuwa
2002-05-15  1:46 jody
2002-05-15  3:16 Nathan Sidwell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20020319175836.8358.qmail@sources.redhat.com \
    --to=jody@ifi.unizh.ch \
    --cc=gcc-gnats@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).