Boost logo

Boost :

Subject: Re: [boost] [contract] invariant checking after destructor throw
From: Dave Abrahams (dave_at_[hidden])
Date: 2012-09-03 16:47:56


on Tue Aug 28 2012, Andrzej Krzemienski <akrzemi1-AT-gmail.com> wrote:

> I have found a potential issue while reading the documentation. (The
> documentation is very good BTW). It says that the non-static invariant is
> still checked if object's destructor throws an exception. Am I reading it
> right? If so, I believe this is not correct. I have two problems with it:
>
> 1. According to the standard, an object is considered destroyed (its
> life-time has ended) when its destructor *starts*. Even if it throws an
> exception, it is considered destroyed, so accessing its members (in order
> to check for the invariant) may be illegal (an undefined behavior).

It's not undefined behavior. The members and bases are not yet
destroyed. Otherwise, how would you release any resources held in
mmebers?

> 2. Why such an object (that threw on destruction) would need to preserve
> the invariant? You cannot access it or use it or even destroy it the second
> time, because it has already been destroyed. No-one will notice it anyway.

This is still a good question.

-- 
Dave Abrahams
BoostPro Computing                  Software Development        Training
http://www.boostpro.com             Clang/LLVM/EDG Compilers  C++  Boost

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk