Bug 24802 – misleading "cannot `goto` into `try` block" when skipping variable with destructor

Status
NEW
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-10-09T13:49:55Z
Last change time
2024-12-13T19:37:59Z
Keywords
diagnostic
Assigned to
No Owner
Creator
Manu
See also
https://issues.dlang.org/show_bug.cgi?id=24300
Moved to GitHub: dmd#18274 →

Comments

Comment #0 by turkeyman — 2024-10-09T13:49:55Z
struct S { ~this() nothrow; } void test() nothrow { goto skip; S r; skip: } error : cannot `goto` into `try` block test() is nothrow, S.~this() is nothrow. There should be no `try` blocks in sight... the message should be about skipping initialisation.
Comment #1 by dkorpel — 2024-10-09T15:34:27Z
The compiler rewrites things that happen on scope exit (such as destructors) into try-finally blocks. The same happens with scope guards: ``` void main() { goto x; scope(exit) {} x: } ``` See also issue 24300. The solution is probably to add a field to the lowered AST node keeping track of where a try-finally block came from.
Comment #2 by turkeyman — 2024-10-11T08:45:27Z
Is that efficient? Does that affect optimisation opportunities in any way?
Comment #3 by robert.schadek — 2024-12-13T19:37:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/18274 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB