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 04:29:48 PDT 2013


Hi,

DMD (I'm using v2.060) seems to evaluate conditions in static 
if's from top to bottom (at least in a given scope). For example, 
consider the following program:

   module test;

   const bool x = true;
   const bool y = true;

   struct S {

     static assert(y);

     static if(x)
        static const bool y = false;

     static if(y)
        static const bool x = false;
   }

'x' in the first static if condition refers to .x and the static 
if introduces S.y to which 'y' in the second static if refers. 
'y' in the static assert also refers to S.y and thus the 
assertion fails:

   test.d(8): Error: static assert  (y) is false

Now, I guess if the second static if were evaluated first then 
'y' in the static assert condition would refer to .y and the 
program would compile. Note that dmd evaluates the static assert 
*after* both static if's.

So clearly D program semantics depends on the order static if's 
and static assert's are evaluated. Are there any standard rules 
here (I cannot find anything in Language Reference) or is this 
behaviour implementation dependent?

Artur


More information about the Digitalmars-d mailing list