[Issue 2048] DMD crash on CTFE that involves assigning to member variables of void-initialized struct

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Jul 18 02:22:45 PDT 2008


http://d.puremagic.com/issues/show_bug.cgi?id=2048


2korden at gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
            Summary|Code causes DMD to crash    |DMD crash on CTFE that
                   |                            |involves assigning to member
                   |                            |variables of void-
                   |                            |initialized struct




------- Comment #1 from 2korden at gmail.com  2008-07-18 04:22 -------
Is this code a correct D in the first place?

struct Number
{
    static Number opCall()
    {
        Number n = void;
        return n;
    }
}

class Crash
{
    Number number = Number();
}

crash.d(6): Error: variable n is used before initialization
crash.d(12): Error: cannot evaluate opCall() at compile time

If it isn't and variable can't use void initializer for expression to work in
compile time, then the fix is trivial.

But I think that it should work. IIRC, if you initialize a variable with void
it means "initialize with anything, I don't care" so that compiler could simply
increase stack pointer instead of putting some meaningful values to stack for a
variable to initialize, or do some other optimization. If it is, then a void
initializer can be ignored for CTFE and a variable can be initialized with a
zero- or default initializer, since both belongs to/are subset of "any
initializer". Moreover CTFE should have determinative behavior.

Adding something like this:
if ((v->value == NULL) && (v->init->isVoidInitializer()) {
        v->value = v->type->defaultInit();
}
solved the problem and compiled both samples for me.


-- 



More information about the Digitalmars-d-bugs mailing list