Should scope(exit) be valid outside of a scope?
Don
nospam at nospam.com
Tue May 11 13:18:29 PDT 2010
Consider the following code
----------
import std.stdio;
void foo(bool x)
{
if (x)
scope(exit) writeln("exiting");
writeln("body");
}
----------
If the scope(exit) isn't in a compound statement (ie, if it isn't inside
{}), the 'scope' applies only to the statement itself, so that's
identical to:
if (x) writeln("exiting");
which is useless and probably not what was intended.
Ditto for scope(success).
Currently the scope(exit) doesn't get executed at all (it's bugzilla
1894). But I suspect that any such use of scope guards is a bug.
Can we just make it illegal?
More information about the Digitalmars-d
mailing list