From 8554287935781614024
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,96a8c01f7043c2d9
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 2002-09-27 05:12:09 PST
Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!kibo.news.demon.net!mutlu.news.demon.net!demon!mail2news.demon.co.uk!devnull
From: glancaster@ntlworld.com ("Garry Lancaster")
Newsgroups: comp.std.c++
Subject: Re: Proposal: exception stack unwinding resumption
Date: Fri, 27 Sep 2002 11:53:54 +0000 (UTC)
Organization: ntl Cablemodem News Service
Lines: 130
Approved: fjh@cs.mu.oz.au (Fergus Henderson , moderator of comp.std.c++)
Message-ID: <gGVk9.2334$sh4.110044@newsfep2-win.server.ntli.net>
References: <6df0c6a8.0208260746.633710cb@posting.google.com><23b84d65.0209161107.23bea618@posting.google.com><6df0c6a8.0209170602.2cb54634@posting.google.com><RW_h9.899$nU2.53545@newsfep1-gui.server.ntli.net><6df0c6a8.0209201925.6faa9e57@posting.google.com><c87c1cfb.0209220939.46d823af@posting.google.com><6df0c6a8.0209230602.2aba3ca8@posting.google.com><c87c1cfb.0209231924.6b639ab2@posting.google.com><6df0c6a8.0209240716.6fb5ec00@posting.google.com><c87c1cfb.0209252107.70dc6f8e@posting.google.com> <ZRjjgCB9B1k9Ewft@robinton.demon.co.uk>
X-Trace: mail2news.demon.co.uk 1033127634 4269 10.0.0.1 (27 Sep 2002 11:53:54 GMT)
X-Complaints-To: abuse@demon.net
NNTP-Posting-Date: Fri, 27 Sep 2002 11:53:54 +0000 (UTC)
X-Received: from mulga.cs.mu.oz.au ([128.250.1.22])
	by news.demon.co.uk with esmtp (Exim 4.05)
	id 17utgu-00016i-00
	for mail2news@news.news.demon.net; Fri, 27 Sep 2002 11:53:52 +0000
X-Received: from localhost (localhost [[UNIX: localhost]]) by mulga.cs.mu.OZ.AU
	id VAA29313; Fri, 27 Sep 2002 21:53:19 +1000 (EST)
X-Authentication-Warning: mulga.cs.mu.OZ.AU: fjh set sender to devnull@stump.algebra.com using -f
X-Path: comp-std-cpp-robomod!not-for-mail
X-Robomod: STUMP, ichudov@algebra.com (Igor Chudov)
X-Delivered-To: std-c++@ncar.ucar.edu
X-Newsgroups: comp.std.c++
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
X-NNTP-Posting-Date: Fri, 27 Sep 2002 10:38:20 BST
X-MailScanner: PASSED (v1.2.6 65811 g8R9cT3e082122 mailbox1.ucsd.edu)
Xref: archiver1.google.com comp.std.c++:14258

Pierre Baillageon:
> >> I'd like to be corrected if I'm wrong, but I'm quite certain that if
> >> ~A() throws, all its data members and base classes are destructed. The
> >> relevant clause, I believe, is 15.2, where it is said that partially
> >> constructed objects will have their fully constructed parts destroyed
> >> properly. It even mention that it works for arrays.

Bob Bell:
> >I don't have a copy of the standard, but I'll give you my
> >understanding of the language. Perhaps someone else who does have the
> >standard can settle this for us.
> >
> >"Partially constructed objects" refers to exceptions that are thrown
> >by a constructor, not a destructor. The intent is for the language to
> >guarantee that objects the programmer cannot access are destroyed
> >(since the object has not yet finished constructing, the programmer
> >has not been able to obtain a reference to it).
> >
> >If an exception is thrown from some function that is _not_ a
> >constructor, then only stack objects are destroyed. Therefore, if
> >A::~A above throws, since the B part is not a stack object, B::~B will
> >not be called.
> >
> >I'd be interested in anybody else's opinion on this as well. I just
> >ran a quick test in CodeWarrior 7, and it seems to agree with my
> >interpretation.

Francis Glassborow:
> I am not sure that the Standard actually deals with this. There quite a
> number of corner problems with dtors which matter not at all until
> people want to push the boundaries. But it matters not, because
> supposing that the base subobject dtors are called all they do is make
> matters worse by ensuring that you have a ghost object with some of its
> limbs missing.
>
> However I have just looked up the requisite part of the C++ Standard.
> 15.2 para 2 starts:
>
> An object that is partially constructed or partially destroyed will have
> destructors executed for all of its fully constructed subobjects, that
> is, for subobjects for which the constructor has completed execution and
> the destructor has not yet begun execution.
>
> That makes it quite clear either CodeWarrior got it wrong or your test
> is faulty.

There are two more possibilities:

1. We misinterpret the standard.
2. The standard has a defect.

Let's say we have something like this:

#include <iostream>
#include <string>
#include <exception>

class B
{
public:
 ~B()
    {
     std::cout << "~B\n";
        if( std::uncaught_exception() ) std::cout << "Unwinding.\n";
        throw std::string( "~B" );
    }
};

class A : public B
{
public:
 ~A()


  std::cout << "~A\n";
  throw std::string( "~A" );
 }
};

int main()
{
 try
 {
  A a;
    }
    catch(const std::string s)
    {
     std::cout << "Caught exception thrown by " << s << ".\n";
    }
    std::cout << "Exiting normally.\n";
}

If I understand Bob Bell's reasoning correctly, he is saying that
the program should print:

~A
Caught exception thrown by ~A.
Exiting normally.

I wonder if CodeWarrior 7 would agree?

MSVC7 gives:

~A
~B
Unwinding.

then terminates.

and Borland C++ Builder 5 gives:

~A
~B

then terminates.

Make of this what you will.

Kind regards

Garry Lancaster
Codemill Ltd
Visit our web site at http://www.codemill.net

---
[ comp.std.c++ is moderated.  To submit articles, try just posting with ]
[ your news-reader.  If that fails, use mailto:std-c++@ncar.ucar.edu    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html                       ]



