Bug 8741 – wrong code for struct member initialized using struct constructor
Status
RESOLVED
Resolution
FIXED
Severity
major
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-09-30T16:42:00Z
Last change time
2013-02-17T02:08:21Z
Keywords
pull, wrong-code
Assigned to
nobody
Creator
peter.alexander.au
Comments
Comment #0 by peter.alexander.au — 2012-09-30T16:42:16Z
struct Vec2
{
this(float x)
{
m[0] = x;
m[1] = x;
}
float[2] m;
static Vec2 zeroes = Vec2(0);
}
void main()
{
import std.stdio;
writeln(Vec2.zeroes);
}
Output is:
Vec2([0, nan])
http://dpaste.dzfl.pl/77058efc
Using two parameters for the constructor makes the bug go away:
http://dpaste.dzfl.pl/7ea20ba0
Comment #1 by clugdbug — 2012-10-02T00:04:08Z
Was "CTFE: Incorrect static array assign results in constructor"
This doesn't involve CTFE, it's a semantic error. It is deciding if Vec2(0) is a struct literal or a constructor, before it has worked out that Vec2 even has a constructor. So it decides (incorrectly) that it's a struct literal.
It doesn't require static arrays, either. The constructor just doesn't get called at all.