Bug 6524 – Ternary operator fails to recognise implicitly convertible function pointers
Status
RESOLVED
Resolution
DUPLICATE
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
All
Creation time
2011-08-18T01:33:00Z
Last change time
2011-08-18T08:50:27Z
Keywords
rejects-valid
Assigned to
nobody
Creator
bugzilla
Comments
Comment #0 by bugzilla — 2011-08-18T01:33:09Z
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 by yebblies — 2011-08-18T08:50:27Z
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 ***