[cfe-dev] [LLVMdev] [LLVMDev] Object in a try-catch block not being destroyed even after an exception

John McCall rjmccall at apple.com
Tue Jun 19 16:48:21 PDT 2012

On Jun 19, 2012, at 3:27 PM, Richard Smith wrote:
> b is constructed, since its constructor has finished.
> However, the problem seems to be a bit more subtle. When we get to the
> destructors at the end of the full-expression, the two 'a' temporaries
> and 'tmp' have been constructed. In normal execution, we would then
> destroy the 'a' temporaries in reverse construction order, and then
> destroy the 'tmp' object at the end of its scope.
> Now, GCC seems to believe that after the first '~a' call throws, we
> should destroy 'tmp' and then destroy the 'a' temporary. Perhaps it's
> trying to enforce reverse construction order ('tmp' was constructed
> after the 'a' temporaries), per 15.2/1. However, that paragraph does
> not directly apply, since temporaries don't have automatic storage
> duration (see core issue 365).

I don't find the reasoning in this core issue convincing, and I agree
with Steve Adamczyk's comment that it's really just their object lifetime
that's a bit odd, not their storage duration.

I believe the intent of the standard is quite clearly to have the local
variable destroyed in reverse order of construction w.r.t. the temporaries,
much like a return value must be.  Clang doesn't get either of these


More information about the cfe-dev mailing list