Bug 4313 – (D1 only) undefined identifier error with scope guard statement

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
All
OS
All
Creation time
2010-06-14T11:45:44Z
Last change time
2019-07-13T10:02:33Z
Keywords
accepts-invalid
Assigned to
No Owner
Creator
Trass3r

Comments

Comment #0 by hoganmeier — 2010-06-14T11:45:44Z
import std.stdio; void main() { scope(exit) writeln(res); auto res = 0; } This compiles, but using failure or success in the scope guard statement gives "undefined identifier res". The question is, if this case is an accepts-invalid or if the other two cases are rejects-valid.
Comment #1 by hoganmeier — 2010-06-14T12:47:08Z
Seems a bit strange. According to CompoundStatement::semantic this is rewritten as try-catch-finally. Even scope(exit) would have the auto res = 0 in the try block which would result in undefined identifier.
Comment #2 by yebblies — 2012-01-30T19:02:11Z
(In reply to comment #1) > Seems a bit strange. According to CompoundStatement::semantic this is rewritten > as try-catch-finally. > > Even scope(exit) would have the auto res = 0 in the try block which would > result in undefined identifier. Because the declaration is nothrow, main's body becomes: { int res = 0; writeln(res); return 0; } But yes, this is a bug.
Comment #3 by k.hara.pg — 2014-05-27T07:24:33Z
In git head (2.066a), the issue is properly fixed by the change: https://github.com/D-Programming-Language/dmd/pull/3564
Comment #4 by pro.mathias.lang — 2019-07-13T10:02:33Z
Indeed fixed in D2