1315 – CTFE doesn't default initialise arrays of structs

D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 1315 - CTFE doesn't default initialise arrays of structs
Summary: CTFE doesn't default initialise arrays of structs
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D1 (retired)
Hardware: x86 Windows
: P2 normal
Assignee: Walter Bright
URL:
Keywords:
Depends on:
Blocks:
Reported: 2007年07月05日 10:43 UTC by Don
Modified: 2014年02月16日 15:23 UTC (History)
0 users

See Also:


Attachments
Add an attachment (proposed patch, testcase, etc.)

Note You need to log in before you can comment on or make changes to this issue.
Description Don 2007年07月05日 10:43:22 UTC
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();
}
Comment 1 Walter Bright 2007年09月28日 22:06:39 UTC
Fixed dmd 1.021 and 2.004


AltStyle によって変換されたページ (->オリジナル) /