Stack overflow

Alex Rønne Petersen alex at lycus.org
Fri Jun 22 03:28:53 PDT 2012


On 22-06-2012 12:22, Namespace wrote:
> I have this code:
> http://codepad.org/vz17iZrm
>
> And as long as i comment out the assert's in the constructor on line 10
> and the assert in the invariant on line 16 it works as i want.
> But otherwise the compiler prints stackoverflow and that's all.
>
> Why and how is the stack overflowed with an simple assert?!

Wow, you really managed to dig up some compiler bugs here.

OK, so first of all, if you change the asserts to assert(obj); and 
assert(_obj); (I assume this is what you meant in the invariant), the 
code compiles. This is clearly a bug.

Now, if you change the first assert to assert(obj); and the one in the 
invariant to assert(obj); *too* (invalid code), the compiler just plain 
seg faults.

The workaround, as mentioned, is to either use assert(obj); and 
assert(_obj); or assert(!!obj); and assert(!!_obj);. The reason the 
latter forms may be desirable is that the former calls obj's invariant 
in addition to checking for null. The latter doesn't.

In any case, please file bugs for these issues. You really managed to 
run into some unusually broken parts of the compiler, it seems. :-/

-- 
Alex Rønne Petersen
alex at lycus.org
http://lycus.org


More information about the Digitalmars-d-learn mailing list