Bug 24466 – `scope(exit)` should not be allowed in the main scope of `noreturn` functions

Status
NEW
Severity
minor
Priority
P1
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2024-03-29T07:08:11Z
Last change time
2024-12-13T19:34:17Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
basile-z
Moved to GitHub: dmd#20430 →

Comments

Comment #0 by b2.temp — 2024-03-29T07:08:11Z
consider the following code ```d noreturn v(int a) { scope(exit) a++; // cant be executed { scope(exit) a++; // this one is okay } assert(0); } ``` There should be a sema error for the first scope guard as the defered expression statement cannot be executed.
Comment #1 by elpenguino+D — 2024-03-29T07:18:37Z
I don't think it's accurate to do that for all noreturn scopes. Consider: ``` noreturn v(int a) { scope(exit) a++; { scope(exit) a++; } throw new Exception("Exception"); } ``` In this code, both scope guards should be executed.
Comment #2 by robert.schadek — 2024-12-13T19:34:17Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20430 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB