Difference betwee storage class and type (invariant/const)?

Christian Kamm kamm.incasoftware at shift-at-left-and-remove-this.de
Tue Jun 19 02:39:40 PDT 2007


>> For example, what do these do differently?
>> 
>> invariant int foo;
>> invariant(int) foo;
> 
> Nothing.

I thought so too, but experimenting with the new compiler gives

void main()
{
  invariant int foo;
  invariant(int) bar;
  static if(is(typeof(foo) == typeof(bar)))
    pragma(msg, "Same types");

  bar = 1;
  foo = 1; // line 9
}

dmd invartest
Same types
invartest.d(9): Error: constant foo is not an lvalue

So... they are the same type but behave differently? Is that a bug?

Christian


More information about the Digitalmars-d-learn mailing list