www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 15190] New: scope(success/failure) are oddly implemented and


          Issue ID: 15190
           Summary: scope(success/failure) are oddly implemented and mask
                    stack traces
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Severity: major
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: thecybershadow gmail.com

Created attachment 1558
  --> https://issues.dlang.org/attachment.cgi?id=1558&action=edit
Demonstration program

scope statements seem to be rethrowing exceptions, or otherwise causing them to
be (re)thrown them from within the stack frame of the function containing the
scope statement, and not the function where the exception was thrown. This
causes loss of information on the exception's origin, which makes debugging
difficult. This is especially severe when the exception does not itself contain
a stack trace (e.g. it's an OutOfMemoryError or an

I'm attaching a demonstration program. To reproduce the issue, compile the
program (and specify one of the defined versions), start it under gdb and run
"break _d_throwc", "run" and "where". Depending on the version specified, the
f!int function invocations will or will not be visible in the stack trace
displayed by gdb.

Here are my results (Linux, DMD64 v2.068.1, gdb 7.7.1):

Version | f!int visible? | Description
test0   | Yes            | No scope/try blocks
testSS  | No             | scope(success)
testSF  | No             | scope(failure)
testSX  | Yes            | scope(exit)
testTN  | Yes            | try/catch
testTF  | Yes            | try/finally

From what was tested, only scope(success) and scope(failure) rethrew the
exception from main(). Things of note: 1. As far as I can see, scope(success) has no reason to interfere with exceptions at all, all it should do is virtually insert code before every return point in the function. 2. scope(exit) displays the full stack trace, despite that it is simply the union of scope(success) and scope(failure). --
Oct 11 2015