Bug 20506 – [DIP1000] scope variable cannot be thrown

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2020-01-15T13:43:24Z
Last change time
2024-12-13T19:06:50Z
Keywords
safe
Assigned to
No Owner
Creator
Mathias LANG
Moved to GitHub: dmd#19659 →

Comments

Comment #0 by pro.mathias.lang — 2020-01-15T13:43:24Z
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).
Comment #1 by dkorpel — 2021-07-11T23:43:47Z
It's not that obvious, checking nothrow is not enough. This is not allowed: ``` void main () @safe @nogc nothrow { try { scope exc = new Exception("Baguette"); throw exc; } catch (Exception e) { assert(e is exc); } } ``` There needs to be a check whether the try-catch block that catches the exception is inside the scope of the variable that is being thrown.
Comment #2 by robert.schadek — 2024-12-13T19:06:50Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19659 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB