Bug 4304 – default arguments using delegates of a global object no longer work

Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D1 (retired)
Platform
Other
OS
Mac OS X
Creation time
2010-06-13T09:48:00Z
Last change time
2010-09-13T23:57:26Z
Assigned to
nobody
Creator
fawzi

Comments

Comment #0 by fawzi — 2010-06-13T09:48:53Z
with dmd 1.062 {{{ class A{ int f(int a){ return a; } static A defaultA; static this(){ defaultA=new A(); } } void f(int delegate(int) arg=&A.defaultA.f){ arg(2); } void defaultCall(){ f(); } }}} fails with Error: cannot inline default argument &defaultA.f whereas it did work previously. This might be indeed correct if the compiler cannot guarantee that the correct value of defaultA is used (i.e. after the static initializer). It seemed to work correctly in my use case, and the fact that setting defaultA to another value is most probably not "seen" by default value shows that using null as default value, and an if (arg is null) arg=&A.defaultA.f; in the body is probably a better solution. I still submit it here, but most likely this change is a feature, not a bug.
Comment #1 by clugdbug — 2010-09-13T23:57:26Z
Same root cause as bug 4820. *** This issue has been marked as a duplicate of issue 4820 ***