D issues are now tracked on GitHub. This Bugzilla instance remains as a read-only archive.
Issue 6524 - Ternary operator fails to recognise implicitly convertible function pointers
Summary: Ternary operator fails to recognise implicitly convertible function pointers
Status: RESOLVED DUPLICATE of issue 3180
Alias: None
Product: D
Classification: Unclassified
Component: dmd (show other issues)
Version: D2
Hardware: Other All
: P2 normal
Assignee: No Owner
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2011-08-18 01:33 UTC by Lars T. Kyllingstad
Modified: 2011-08-18 08:50 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 Lars T. Kyllingstad 2011-08-18 01:33:09 UTC
Test case:

    int foo() { return 0; }
    int bar() @safe pure nothrow { return 1; }

    void main()
    {
        bool b;
        auto fptr = b ? &foo : &bar;
    }

Since @safe, pure and nothrow function pointers are implicitly convertible to function pointers without these attributes, the above should compile just fine.  Instead, dmd gives the following error:

    test.d(7): Error: incompatible types for ((& foo) ? (& bar)):
    'int function()' and 'int function() pure nothrow @safe'
Comment 1 yebblies 2011-08-18 08:50:27 UTC
The patch/pull request for this has been sitting in github for a couple of months now.

*** This issue has been marked as a duplicate of issue 3180 ***