Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warnings when compiling with -ffinite-math-only on Linux with Clang v19.1 #241

Open
theakman2 opened this issue Nov 13, 2024 · 2 comments
Open
Assignees
Labels
bug Something isn't working

Comments

@theakman2
Copy link

  • TOML++ version: v3.4.0
  • Compiler: clang++ v19.1.1
  • Target arch: x64
  • Library configuration overrides: None
  • Relevant compilation flags:

You can run the following command on the generated all-in-one toml.hpp file using Clang 19.1:

$ clang++ -ffinite-math-only -fsyntax-only toml.hpp
  • Bug:

When compiling, you get the following warnings:

a@a:/nt$ clang++ -ffinite-math-only -fsyntax-only toml.hpp
/nt/vendor/toml++/toml.hpp:13012:30: warning: use of infinity is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
 13012 |                         return inf ? (negative ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity())
       |                                                   ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/nt/vendor/toml++/toml.hpp:13012:72: warning: use of infinity is undefined behavior due to the currently enabled floating-point options [-Wnan-infinity-disabled]
 13012 |                         return inf ? (negative ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity())
       |                                                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.

Ideally, the parser should generate a parse error on encountering an Inf/NaN when compiling with -ffinite-math-only.

@theakman2 theakman2 added the bug Something isn't working label Nov 13, 2024
@theakman2
Copy link
Author

I started fixing the issue, but it looks like a lot of unit tests need to be updated to check whether finite-math-only is enabled. Unfortunately I don't have enough time to make these changes, but hopefully my fork is helpful if you decide to address this.

@marzer
Copy link
Owner

marzer commented Nov 14, 2024

Ideally, the parser should generate a parse error on encountering an Inf/NaN when compiling with -ffinite-math-only.

Hmm, maybe. The problem with doing this is you can no-longer round-trip a config document that contains NaN/Inf if you all you're doing is modifying some other non-float field.

The TOML spec mandates that floating points are IEEE 754 format, and the library is already capable of detecting these regardless of the compilers attitude towards them (ref). All that's missing here is the other side of the round-trip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants