[Issue 20506] New: [DIP1000] scope variable cannot be thrown

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Jan 15 13:43:24 UTC 2020


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 at puremagic.com
          Reporter: pro.mathias.lang at 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).

--


More information about the Digitalmars-d-bugs mailing list