www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 20506] New: [DIP1000] scope variable cannot be thrown

https://issues.dlang.org/show_bug.cgi?id=20506

          Issue ID: 20506
           Summary: [DIP1000] scope variable cannot be thrown
           Product: D
           Version: D2
          Hardware: All
                OS: All
            Status: NEW
          Keywords: safe
          Severity: normal
          Priority: P1
         Component: dmd
          Assignee: nobody puremagic.com
          Reporter: pro.mathias.lang gmail.com

Code:

```
void main ()  safe  nogc nothrow
{
    scope exc = new Exception("Baguette");
    try {
        throw exc;
    } catch (Exception e) {
        assert(e is exc);
    }
}
```

Result:
bug.d(5): Error: scope variable exc may not be thrown

The code is obviously ` safe`: While a scope variable is thrown, the function
itself is nothrow, meaning the function cannot escape the scope of this
function (even if passed down to another function).

--
Jan 15 2020