Bug 8496 – Assignment of function literal to function pointer variable with non-D linkage broken

Status
RESOLVED
Resolution
FIXED
Severity
enhancement
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2012-08-02T13:00:00Z
Last change time
2012-10-28T02:14:03Z
Keywords
pull
Assigned to
k.hara.pg
Creator
alex

Comments

Comment #0 by alex — 2012-08-02T13:00:58Z
This used to work in 2.059. alexrp@alexrp ~/Projects/tests $ dmd test.d test.d(8): Error: cannot implicitly convert expression (__lambda1) of type void function() pure nothrow @safe to extern (C) void function() alexrp@alexrp ~/Projects/tests $ cat test.d alias extern (C) void function() Func; void main() { Func f; f = () { }; }
Comment #1 by k.hara.pg — 2012-09-22T03:23:45Z
This is not a regression. In 2.059, this was accidentally allowed by the cause same with bug 8397. It's already fixed in 2.060. (Therefore, the call of function pointer f might had been broken in 2.059) And, lambda type inference does not infer function linkage in current implementation. Then, (){} is always extern(D), and the error is expected. But, it is reasonable feature. So I change the importance to 'enhancement'.
Comment #2 by k.hara.pg — 2012-09-22T03:26:34Z
I'd like to update sample code. alias extern (C) void function() FP; void main() { FP fp = (){}; fp = (){}; } The fp declaration and assignment should infer the lambda's linkage.
Comment #3 by k.hara.pg — 2012-09-22T11:23:46Z
Comment #4 by yebblies — 2012-10-28T02:14:03Z