From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 5782 invoked by alias); 15 May 2002 10:16:04 -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 5768 invoked by uid 71); 15 May 2002 10:16:03 -0000 Date: Wed, 15 May 2002 03:16:00 -0000 Message-ID: <20020515101603.5767.qmail@sources.redhat.com> To: nobody@gcc.gnu.org Cc: gcc-prs@gcc.gnu.org, From: Nathan Sidwell Subject: Re: c++/6006: problem with pure virtual functions and destructord Reply-To: Nathan Sidwell X-SW-Source: 2002-05/txt/msg00412.txt.bz2 List-Id: The following reply was made to PR c++/6006; it has been noted by GNATS. From: Nathan Sidwell To: jody@ifi.unizh.ch Cc: lerdsuwa@gcc.gnu.org, gcc-bugs@gcc.gnu.org, gcc-prs@gcc.gnu.org, nobody@gcc.gnu.org, gcc-gnats@gcc.gnu.org Subject: Re: c++/6006: problem with pure virtual functions and destructord Date: Wed, 15 May 2002 11:06:07 +0100 jody@ifi.unizh.ch wrote: > > Hi > Is there a particular reason why a a virtual function called > in a destructor is the function of this class and not the derived class? because the standard says so. > (There are implementations of C++ where the virtual > function of the derived class is called) those implementations are buggy. > In my example, however, the function g() calls the pure virtual > function f(). But g() can be called from the destructor of A, > without causing a problem. neither call 'works'. Drat, someone's borrowed my c++ std, so this is from memory. in the dtor of A, the B object is not complete (B's dtor has been executed, modulo the bits pertaining to its bases). We shouldn't call (non-static) member functions of B, because there's no constructed B object for their this pointer to point to. The std says, that in this case, virtual functions dispatch to the function seen in the definition of the base being ctor'd or dtor'd (i.e. what the final overrider would be if that base was the complete object). IIRC, calling a pure virtual function is undefined, so anything can happen. g++ 3.0 reports 6006.cc:37: abstract virtual `virtual void A::f()' called from destructor because it can prove that that resolved to a pure virtual. It cannot do so for the one embedded in g, but if you executed such a program it would fail. nathan -- Dr Nathan Sidwell :: Computer Science Department :: Bristol University The voices in my head told me to say this nathan@acm.org http://www.cs.bris.ac.uk/~nathan/ nathan@cs.bris.ac.uk