Bug 23411 – ImportC: undefined identifier __builtin_nanf

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P3
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2022-10-13T22:42:40Z
Last change time
2023-12-19T14:33:18Z
Keywords
ImportC, pull
Assigned to
No Owner
Creator
dave287091

Comments

Comment #0 by dave287091 — 2022-10-13T22:42:40Z
The following C file fails to compile #include <math.h> float x = NAN; // Error: undefined identifier `__builtin_nanf`, did you mean template `__builtin_inf()()`? On macOS, the standard C macro NAN is defined as: #define NAN __builtin_nanf("0x7fc00000") On x64 linux, it is defined as: # define NAN (__builtin_nanf ("")) So the above file preprocesses to: float x = __builtin_nanf("0x7fc00000"); Looking at https://gcc.gnu.org/onlinedocs/gcc/Other-Builtins.html, there’s also __builtin_nan and __builtin_nanl.
Comment #1 by dave287091 — 2022-10-14T02:53:50Z
Note that adding: alias __builtin_nan = imported!"core.stdc.math".nan; alias __builtin_nanf = imported!"core.stdc.math".nanf; alias __builtin_nanl = imported!"core.stdc.math".nanl; to __builtins.di does *not* solve the issue as then it cannot be used as a static initializer: Error: `nanf` cannot be interpreted at compile time, because it has no available source code.
Comment #2 by dlang-bot — 2023-12-17T01:20:59Z
@WalterBright created dlang/dmd pull request #15918 "fix Issue 23411 - ImportC: undefined identifier __builtin_nanf" fixing this issue: - fix Issue 23411 - ImportC: undefined identifier __builtin_nanf https://github.com/dlang/dmd/pull/15918
Comment #3 by dlang-bot — 2023-12-19T14:33:18Z
dlang/dmd pull request #15918 "fix Issue 23411 - ImportC: undefined identifier __builtin_nanf" was merged into master: - c714f745d546e68638eaccc0db2118bdad1dc484 by Walter Bright: fix Issue 23411 - ImportC: undefined identifier __builtin_nanf https://github.com/dlang/dmd/pull/15918