← Back to index
|
Original Bugzilla link
Bug 3622 – Nested structs as default function arguments not initialized
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Windows
Creation time
2009-12-16T13:44:00Z
Last change time
2015-06-09T01:27:03Z
Assigned to
nobody
Creator
tomeksowi
Comments
Comment #0
by tomeksowi — 2009-12-16T13:44:35Z
Strangely enough it happens only if the nested struct is forward referenced. Looks like the default argument is not initialized at all in these cases. Testcase (should pass): struct Strukt { int pole; Wsk wsk; this(int pole, Wsk wsk = Wsk()) { this.pole = pole; this.wsk = wsk; } static Wsk zla_funkcja(uint i, Wsk wsk = Wsk()) { return wsk; } struct Wsk { Strukt* w; } static Wsk funkcja(uint i, Wsk wsk = Wsk()) { return wsk; } } void main() { auto ok = Strukt.funkcja(7); assert(!ok.w); // passes auto zly = Strukt.zla_funkcja(7); assert(!zly.w); // boom! auto s = Strukt(6); assert (!s.wsk.w); // boom! }
Comment #1
by clugdbug — 2010-12-08T04:44:34Z
Fixed DMD2.038.