[Issue 1315] New: CTFE doesn't default initialise arrays of structs

d-bugmail at puremagic.com d-bugmail at puremagic.com
Thu Jul 5 08:43:23 PDT 2007


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

           Summary: CTFE doesn't default initialise arrays of structs
           Product: D
           Version: 1.018
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: normal
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: clugdbug at yahoo.com.au


Seems as though struct arrays aren't default initialised inside CTFE.
CTFE disallows concatenation to an unitialised struct array, also can't get the
length.
Workaround is easy - just initialise the array to [].

-----------
struct S {
    int a;
}

int func()
{
/* This is OK
    int [] q;
    q ~=4;
*/
    S [] s; // makes the next lines fail. (but  S[] s = []; compiles).    
    s ~= S(7); // fails
    return s.length; // this fails too
}

void main()
{
    const int x = func();
}


-- 



More information about the Digitalmars-d-bugs mailing list