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 = () { }; }
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'.
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.
https://github.com/D-Programming-Language/dmd/pull/1135
Fixed D2 https://github.com/D-Programming-Language/dmd/commit/a01abef9aafde2b0f155d55af6f1badbfece8920