In what order static if conditions are evaluated?

Artur Zawłocki" <artur.zawlocki at gmail.com> Artur Zawłocki" <artur.zawlocki at gmail.com>
Thu Mar 28 06:34:36 PDT 2013


On Thursday, 28 March 2013 at 11:52:26 UTC, Don wrote:
>
> Yes, it currently evaluates it top to bottom.

As long as all the static if's in question are in a single scope. 
Here dmd evaluates the second (nested) static if before the first 
one:

   static if (S.a) static assert (S.a);

   struct S {
     static if (true) const bool a = true;
   }

> An algorithm has been discussed which would remove that 
> restriction; your example would then compile. It's difficult to 
> implement though. It has to deal with paradoxes:
>
> static if (!is(typeof(x)) int y = 1;
> static if (!is(typeof(y)) int x = 1;
>
> Who wins?

Nice example! Shouldn't the compiler report errors when it 
detects kind of 'circular dependency' between the names occurring 
in static if conditions and the ones declared in their bodies?

Artur



More information about the Digitalmars-d mailing list