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.