json icon indicating copy to clipboard operation
json copied to clipboard

Compiler warning: using infinity leads to undefined behaviour with some floating-point options

Open RSAsterix opened this issue 7 months ago • 2 comments

Description

json.hpp:10652:31: warning: use of infinity is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
 10652 |                             ? std::numeric_limits<double>::infinity()

Some floating point compiler options do not agree with the usage of std::numeric_limits::infinity()

Reproduction steps

Compile with (Apple) Clang with -ffast-math enabled

Expected vs. actual results

My expectation would be that json.hpp doesn't trigger -Wnan-infinity-disabled

Minimal code example


Error messages


Compiler and operating system

Apple clang version 17.0.0 (clang-1700.0.13.5) Target: arm64-apple-darwin24.5.0

Library version

3.12.0

Validation

RSAsterix avatar Jun 02 '25 13:06 RSAsterix

My expectation would be that json.hpp doesn't trigger -Wnan-infinity-disabled

I'm not sure that's a reasonable expectation. Asking a library that deals with floating point numbers to never use nan or infinity seems rather odd.

Some useful information: https://simonbyrne.github.io/notes/fastmath/

gregmarr avatar Jun 02 '25 14:06 gregmarr

Thanks @gregmarr. I am also confused. Should the library suppress warnings about features disabled by a client program?

nlohmann avatar Jun 02 '25 15:06 nlohmann

This issue has been marked as stale because it has been open for 90 days without activity. If this issue is still relevant, please add a comment or remove the "stale" label. Otherwise, it will be closed in 10 days. Thank you for helping us prioritize our work!

github-actions[bot] avatar Sep 01 '25 00:09 github-actions[bot]

This issue has been closed after being marked as stale for 10 days without any further activity. If this was done in error or the issue is still relevant, please feel free to reopen it or create a new issue. We appreciate your understanding and contributions.

github-actions[bot] avatar Sep 12 '25 00:09 github-actions[bot]