SysTime and std.array.array

Paolo Invernizzi paolo.invernizzi at gmail.com
Sun Aug 25 07:50:14 PDT 2013


Hi all,

I really missing something here, because the following code is 
taking two different path based on the presence or not of a field 
with SysTime, where the field itself is not involved at all in 
the process.

It seems that I'm using something forbidden, or something that it 
is leading to an undefined behaviour, but I have not idea of what 
it is the source of the problem.

Note that I'm using array() as in the original code I was using 
it over a range, this is a reduction of the same problem.

Suggestions are welcome! http://dpaste.dzfl.pl/fc130984

Paolo Invernizzi

---
import std.datetime;
import std.math;

struct A
{
     double i;
}


struct B
{
     invariant()
     {
		if(j == 0)
			assert(a.i.isNaN, "why is 'j' zero?? and i is not NaN?");
		else
			assert( ! a.i.isNaN );
     }
	
     SysTime when; // comment this line avoid the breakage
     int j;
     A a;
}
void main()
{
     B b1 = B.init;
	assert(&b1); // verify that default eyes invariants are ok;

	auto b2 = B(
		SysTime(0, UTC()),  // comment this line avoid the breakage
		1, A(1));
	assert(&b2);
	auto b3 = B(
		SysTime(0, UTC()),  // comment this line avoid the breakage
		1, A(1)
	);
	assert(&b3);
	
     import std.array;
     auto arr = [b2, b3];
	
	assert(arr[0].j == 1);
	assert(arr[1].j == 1);
     auto a2 = arr.array(); // << bang, invariant is raised, also 
if b2 and b3 are good
}
--


More information about the Digitalmars-d-learn mailing list