-
Notifications
You must be signed in to change notification settings - Fork 297
Description
When compiling a C++ project that transitively only has math.h included, the SIMDe language detection fails to detect the correct environment and thus uses symbols that aren't actually available:
include\simde\simde-math.h(413,7): error C2039: 'isnan': is not a member of 'std'
Both cmath and math.h are wrappers around corecrt_math.h in Microsoft's standard library, which uses macros when used in a C language project and template functions when used in a C++ language project (official documentation):
When compiled as C++, the isnan macro isn't defined, and an isnan template function is defined instead. It behaves the same way as the macro, but returns a value of type bool instead of an integer.
This leads to the following chain of events:
- Some transitive header might include
math.h, which includescorecrt_math.h - Because the project language is C++ and
__cplusplus_is defined, the header will not set up aisnanmacro, but a template function - Because
cmathis not included, those templated math functions are not added to thestdnamespace - SIMDe will neither detect a
isnanmacro nor the libc++ header guards, but will detect__cplusplusand assume thatcmathis included - Because of this the simde aliases will attempt to use
std::isnaneven thoughisnanonly exists as a templated function
So the underlying assumption that the absence of a isnan macro also means that <cmath> was included and thus the associated math functions exist in the std namespace are not correct for Microsoft's standard library.
Note that this issue can occur if any header included by any other included header at any point just includes math.h, most possibly when using a pure C library in a C++ project that naively exposes its dependencies in its public headers.