On 03/11/2013 09:19 PM, Jonathan M Davis wrote:
On Monday, March 11, 2013 20:14:07 Timon Gehr wrote:
Actually, in D, static if creates its own scopes for declarations made
inside the static if condition.

No, it doesn't,

Yes it does.

and it would be _way_ less useful if it did,

I don't think so.

particularly with
regards to struct and class definitions. Take this code, for instance,

import std.stdio;

static if(true)
     int var = 7;
else
     string var = 12;

void main()
{
     int i = var;

     static if(is(typeof(var) == int))
         int j = 22;
     else
         float j;

     writeln(j);
}

It compiles just fine and prints 22. Both the static if at module-level and the
one in the function declare variables which are used outside of the static if
blocks. static if does _not_ create a new scope. And putting braces around the
static if bodies has no effect on the scoping either.

...

What is the point? Your example code does not make any declaration inside the static if condition.

Reply via email to