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.
Comment #2 by clugdbug — 2012-10-02T00:26:26Z
Comment #3 by github-bugzilla — 2013-01-02T20:54:43Z
Commit pushed to master at https://github.com/D-Programming-Language/dmd https://github.com/D-Programming-Language/dmd/commit/39207df0a43e1a39a4dcd169505758884cb992d3 Fix issue 8741 wrong code for struct member init using struct ctor Generate an error if we need to decide if it is a ctor or not, when we haven't determined the size yet.
Comment #4 by clugdbug — 2013-01-16T03:07:00Z
*** Issue 3863 has been marked as a duplicate of this issue. ***
Comment #5 by k.hara.pg — 2013-02-17T02:08:21Z
*** Issue 9519 has been marked as a duplicate of this issue. ***