Should scope(exit) be valid outside of a scope?
S
S at S.com
Tue May 11 18:56:52 PDT 2010
On 2010-05-11 13:38:15 -0700, Adam Ruppe said:
> On Tue, May 11, 2010 at 10:18:29PM +0200, Don wrote:
>> 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?
>
> I was pondering named unit tests and wanted to use this:
>
> {
> if(getenv("VERBOSE_TESTS"))
> scope(exit) writefln("Test successful");
> }
>
> But it didn't work. The alternative, scope(exit) if(blah) write; should
> accomplish the same task though.
>
> I'd be good with it being an error, to make it obvious which method is
> preferred.
static if doesn't create a new scope. You should use that instead and
a debug version.
-S
More information about the Digitalmars-d
mailing list