Issue 8496 - Assignment of function literal to function pointer variable with non-D linkage broken
Summary: Assignment of function literal to function pointer variable with non-D linkag...
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: All All
: P2 enhancement
Assignee: Kenji Hara
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2012-08-02 13:00 UTC by Alex Rønne Petersen
Modified: 2012-10-28 02:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description Alex Rønne Petersen 2012-08-02 13:00:58 UTC
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 Kenji Hara 2012-09-22 03:23:45 UTC
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 Kenji Hara 2012-09-22 03:26:34 UTC
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.