Bug 5223 – [qtd] Cannot use default value with function parameter of struct type

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2010-11-16T09:36:00Z
Last change time
2015-03-06T15:07:46Z
Assigned to
nobody
Creator
samukha
See also
http://d.puremagic.com/issues/show_bug.cgi?id=6766

Comments

Comment #0 by samukha — 2010-11-16T09:36:29Z
Struct constructors are disregarded when a struct parameter is constructed out of a default value: struct S2 { } struct S { int x; this(S2 s2) { } void foo(S s = S(S2)) { } } void main() { S s; s.foo(); // error } Error: cannot implicitly convert expression (S2()) of type S2 to int.
Comment #1 by samukha — 2010-11-16T09:48:10Z
Even simpler test-case: struct S { this(int x) { } void foo(S s = S(42)) { } } void main() { S s; s.foo(); // error } Error: more initializers than fields of S
Comment #2 by andrej.mitrovich — 2012-12-18T12:44:39Z
(In reply to comment #1) > Even simpler test-case: This is very similar to Issue 3206. I think what's probably happening is that the semantic analysis on the call expression in a default argument is done without completing the semantic analysis on the struct/class first.
Comment #3 by andrej.mitrovich — 2013-02-10T09:05:19Z
Comment #4 by k.hara.pg — 2015-03-06T15:07:46Z
*** This issue has been marked as a duplicate of issue 6766 ***