Bug 16972 – Issue diagnostic for throwing from a scope(exit) block

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2016-12-14T23:50:30Z
Last change time
2024-12-13T18:50:59Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Ali Cehreli
Moved to GitHub: dmd#19215 →

Comments

Comment #0 by acehreli — 2016-12-14T23:50:30Z
void main() { for (;;) { // It's good that these all produce error messages. (But see issue 16971.) // scope (exit) goto end; // scope (exit) break; // scope (exit) continue; // scope (exit) return; // Unfortunately, this does not issue any diagnostic: scope (exit) throw new Exception(""); } end: } It would be nice if the compiler produced an error message like "throw statements cannot be in scope(exit) bodies" Ali
Comment #1 by dlang-bugzilla — 2017-06-26T00:47:09Z
Is it the compiler or the spec that's wrong? In a trivial test, throwing in a scope(exit) seems to work as expected, and if an exception is already in flight, the new one appears to be correctly chained.
Comment #2 by acehreli — 2017-06-26T01:03:03Z
To complete, the spec says "A scope(exit) or scope(success) statement may not exit with a throw, goto, break, continue, or return; nor may it be entered with a goto." And I found a very long forum thread: http://forum.dlang.org/post/[email protected]
Comment #3 by dlang-bugzilla — 2017-06-26T01:07:35Z
Good find. A pertinent post from that thread: http://forum.dlang.org/post/1237688782434087169.692302SeeWebsiteForEmail-erdan.org@news.digitalmars.com Indeed, it seems facetious to "forbid" throw but allow calling non-nothrow functions, and enforcing the latter is likely to break too much code now. So, we need confirmation that the current compiler implementation is sane and deals with throws properly, after which the spec could be updated.
Comment #4 by robert.schadek — 2024-12-13T18:50:59Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/19215 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB