DMD [-O flag] vs. [memory allocation in a synchronized class]

realhet via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Jun 8 03:20:51 PDT 2017


Hi,

This code works well with the unoptimized compilation with DMD.

import std.array;

synchronized class Obj{
   private int[] arr;
   void trigger(){ arr.length += 1; }
}

void main(){
   auto k = new shared Obj;
   k.trigger;
}

And when I use the -O option, it shows the following error in the 
trigger() method:

core.exception.InvalidMemoryOperationError at src\core\exception.d(696): Invalid memory operation

Why? o.O


More information about the Digitalmars-d-learn mailing list