Bug 10298 – CTFE fails with array literal initialization
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2013-06-08T01:16:00Z
Last change time
2013-06-14T21:08:43Z
Keywords
CTFE, wrong-code
Assigned to
nobody
Creator
bugzilla
Comments
Comment #0 by bugzilla — 2013-06-08T01:16:57Z
The following code works at runtime, but fails when initialized with a literal:
------------------
struct Bug7940 {
int m;
}
struct App7940 {
Bug7940[] x;
}
int bug7940() {
Bug7940[2] y = [Bug7940(),Bug7940()]; // this line causes the failure
//Bug7940[2] y; // works
App7940 app;
app.x = y[0..1];
app.x[0].m = 12;
assert(y[0].m == 12);
assert(app.x[0].m == 12);
return 1;
}
static assert(bug7940()); // fails CTFE
void main()
{
assert(bug7940()); // works at runtime
}
Comment #1 by clugdbug — 2013-06-12T01:38:14Z
Reduced test case
--------------
struct Bug10298 {
int m;
}
int bug10298()
{
Bug10298[2] y = [Bug10298(), Bug10298()];
y[0].m = 6;
assert(y[0].m == 6);
return 1;
}
static assert(bug10298());
Comment #2 by github-bugzilla — 2013-06-14T21:06:07Z