Bug 5305 – Cannot take pointer to intrinsic function
Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
Other
OS
Linux
Creation time
2010-12-01T16:50:30Z
Last change time
2021-08-25T19:27:23Z
Keywords
pull, safe
Assigned to
No Owner
Creator
Bernard Helyer
Comments
Comment #0 by b.helyer — 2010-12-01T16:50:30Z
https://gist.github.com/724508
The code snippet compiles with -release, but not without. In -release mode, the maths intrinsics have the mangling for @safe removed ('Nf'), and so the linker chokes on the mangled signature (because libphobos2.a was compiled with -release.)
A reduced test case:
import std.math;
void map(real function(real) f) { }
void main() { map(&sqrt); }
What is happening here is that sqrt() is an intrinsic, it doesn't actually exist in the libphobos2.a. When compiled with -release, the assert() goes away, and sqrt is never referenced, hence no error.
Without -release, the linker looks for std.math.sqrt, and can't find it because it's an intrinsic.
The solution is one of:
1. have the compiler complain about attempts to take the address of an intrinsic
2. add a library version of the intrinsic
Comment #3 by bearophile_hugs — 2012-01-21T18:50:09Z
(In reply to comment #2)
> The solution is one of:
>
> 1. have the compiler complain about attempts to take the address of an
> intrinsic
>
> 2. add a library version of the intrinsic
Is it possible for the D compiler to use the intrinsic in most cases when sqrt is used directly, and give the pointer to a library sqrt when the programmer uses a &sqrt?
As mentioned by #c2, the issue is taking a pointer to an intrinsic function. Closing as duplicate and renaming for clarity.
*** This issue has been marked as a duplicate of issue 4541 ***
Comment #6 by bugzilla — 2016-06-17T10:50:28Z
The test case I added is to verify that taking the address of sqrt from std.math works.
Comment #7 by github-bugzilla — 2016-06-17T11:56:14Z
dlang/dmd pull request #13016 "test: Remove test case for issue 5305" was merged into master:
- 499d0aa53ac2b4d6a3c39dd7976432de4f926538 by Iain Buclaw:
test: Remove test case for issue 5305
This test is already covered in Phobos std.math
https://github.com/dlang/dmd/pull/13016
Comment #10 by dlang-bot — 2021-08-25T19:27:23Z
dlang/phobos pull request #8210 "std.math: Reference Issue 5305 in unittest taking pointer to function" was merged into master:
- 5a39765c4c5e4c34cd5ee84bae0901af6869d66f by Iain Buclaw:
std.math: Reference Issue 5305 in unittest taking pointer to function
https://github.com/dlang/phobos/pull/8210