Created attachment 1540
Test cases
There are still major issues wrt. proper destruction of temporaries in expression trees in case there are throws. These tests came up when verifying an ongoing LDC implementation.
The attached file allows you to test 5 cases, by passing an arg in [1,5].
Case 1 doesn't feature any throw in the function argument expressions, but features multiple objects with throwing dtors.
Case 2 throws in its last argument expression. The 3 preceeding temporaries should be destructed.
Case 3 is similar to case 2, but 2 of the 3 temporaries throw in their dtors. I guess this should result in all temporary dtors being called (always) and building up an exception chain.
Case 4 already throws in its 2nd argument expression; the single preceeding temporary doesn't throw in its dtor. Case 5 does throw.
Identical results with both DMD 2.067.1 and DMD 2.068-rc1 for Win32:
1) Fine - regular throw in callee, args have been implicitly moved into callee params, callee destructs them. The exceptions in the dtors result in an exception chain:
Test 1:
Constructing a
Constructing b
Constructing c
Constructing d
Destroying a
Destroying b
Destroying c
Destroying d
object.Exception@..\dtor.d(26): foo()!
object.Exception@..\dtor.d(16): dtor a
object.Exception@..\dtor.d(16): dtor c
2&3) No temporaries destructed at all!
Test 2&3:
Constructing a
Constructing b
Constructing c
object.Exception@..\dtor.d(22): make(d)
4) Fine, at last.
Test 4:
Constructing a
Destroying a
object.Exception@..\dtor.d(22): make(b)
5) CRASH at runtime!
Test 5:
Constructing
Destroying a
Destroying a
...
<repetition until crash>
Comment #1 by kinke — 2015-08-10T23:55:05Z
I mixed up cases 2 & 3 - 2 is the one with the 2 throwing dtors, case 3 the one with no throwing dtor.
Apparently there are different results on OSX with DMD 2.068-rc1: no destruction of the single temporary in case 4, but at least no infinite loop in case 5.
Comment #2 by code — 2015-08-11T18:24:58Z
Apparently we both reported an issue within seconds of each other. Closing this one for the one Walter commented on.
*** This issue has been marked as a duplicate of issue 14903 ***