Compile error using synchronized in ldc (but not dmd)

Nikhil Padmanabhan nikhil.padmanabhan at gmail.com
Sun Dec 8 20:25:59 PST 2013


Hello,

The following code snippet fails to compile on ldc2 (0.12.1), but 
successfully compiles on dmd 2.064.2 :

struct Particle {
	double x,y,z,w,x2;
	this(double[] arr) {
		x = arr[0]; y = arr[1]; z=arr[2]; w=arr[3];
		x2 = x*x + y*y + z*z;
	}
}

synchronized class SyncArray {
	private Particle[] buf;

	void push(Particle[] arr1) {
		buf.length = arr1.length;
		buf[] = arr1[];
	}

	Particle[] pop() {
		auto _tmp = new Particle[buf.length];
		_tmp[] = buf[];
		buf = null;
		return _tmp;
	}
}

The error message in ldc2 :
test.d(14): Error: cannot implicitly convert expression (arr1[]) 
of type Particle[] to const(shared(Particle)[])
test.d(19): Error: cannot implicitly convert expression 
(this.buf[]) of type shared(Particle)[] to const(Particle[])

What am I doing wrong here?

Thanks in advance!
-- Nikhil

P.S. I've been enjoying coding in D a lot -- many thanks to the 
entire D community!


More information about the Digitalmars-d-learn mailing list