Skip to content

Commit

Permalink
Fix warning when compiling with -ffinite-math-only in GCC/clang (fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
theakman2 committed Nov 13, 2024
1 parent 380c49f commit 785651b
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ template:
- fixed `is_homogeneous()` overloads with `first_nonmatch` outparam being broken in optimized builds (#231) (@Forbinn)
- fixed unclear error message when parsing integers that would overflow (#224) (@chrimbo)
- fixed CMake `install` target installing `meson.build` files (#236) (@JWCS)
- fixed compilation warnings when compiling with `-ffinite-math-only`in GCC/Clang (#241) (@theakman2)

## v3.4.0

Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ won't need to mess with these at all, but if you do, set them before including t
| `TOML_EXPORTED_MEMBER_FUNCTION` | define | API export annotation to add to non-static class member functions. | undefined |
| `TOML_EXPORTED_FREE_FUNCTION` | define | API export annotation to add to free functions. | undefined |
| `TOML_EXPORTED_STATIC_FUNCTION` | define | API export annotation to add to static functions. | undefined |
| `TOML_FINITE_MATH_ONLY` | boolean | Set to generate a parse error if NaN or Inf floats are encountered. | per compiler settings |
| `TOML_HEADER_ONLY` | boolean | Disable this to explicitly control where toml++'s implementation is compiled (e.g. as part of a library). | `1` |
| `TOML_IMPLEMENTATION` | define | Define this to enable compilation of the library's implementation when `TOML_HEADER_ONLY` == `0`. | undefined |
| `TOML_OPTIONAL_TYPE` | type name | Overrides the `optional<T>` type used by the library if you need [something better than std::optional]. | undefined |
Expand Down
4 changes: 4 additions & 0 deletions include/toml++/impl/parser.inl
Original file line number Diff line number Diff line change
Expand Up @@ -1793,8 +1793,12 @@ TOML_IMPL_NAMESPACE_START
if (cp && !is_value_terminator(*cp))
set_error_and_return_default("expected value-terminator, saw '"sv, to_sv(*cp), "'"sv);

#if TOML_FINITE_MATH_ONLY
set_error_and_return_default("inf/NaN not allowed when compiled with finite math"sv);
#else
return inf ? (negative ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity())
: std::numeric_limits<double>::quiet_NaN();
#endif
}

TOML_NODISCARD
Expand Down
9 changes: 9 additions & 0 deletions include/toml++/impl/preprocessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@
#endif
#endif

// TOML_FINITE_MATH_ONLY
#ifndef TOML_FINITE_MATH_ONLY
#if defined(__FINITE_MATH_ONLY__) && __FINITE_MATH_ONLY__ == 1
#define TOML_FINITE_MATH_ONLY 1
#else
#define TOML_FINITE_MATH_ONLY 0
#endif
#endif

// TOML_CONCAT
#define TOML_CONCAT_1(x, y) x##y
#define TOML_CONCAT(x, y) TOML_CONCAT_1(x, y)
Expand Down
1 change: 1 addition & 0 deletions include/toml++/toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ TOML_POP_WARNINGS;
#undef TOML_EVAL_BOOL_0
#undef TOML_EVAL_BOOL_1
#undef TOML_EXTERNAL_LINKAGE
#undef TOML_FINITE_MATH_ONLY
#undef TOML_FLAGS_ENUM
#undef TOML_FLOAT_CHARCONV
#undef TOML_FLOAT128
Expand Down
14 changes: 14 additions & 0 deletions toml.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,15 @@
#endif
#endif

// TOML_FINITE_MATH_ONLY
#ifndef TOML_FINITE_MATH_ONLY
#if defined(__FINITE_MATH_ONLY__) && __FINITE_MATH_ONLY__ == 1
#define TOML_FINITE_MATH_ONLY 1
#else
#define TOML_FINITE_MATH_ONLY 0
#endif
#endif

// TOML_CONCAT
#define TOML_CONCAT_1(x, y) x##y
#define TOML_CONCAT(x, y) TOML_CONCAT_1(x, y)
Expand Down Expand Up @@ -14284,8 +14293,12 @@ TOML_IMPL_NAMESPACE_START
if (cp && !is_value_terminator(*cp))
set_error_and_return_default("expected value-terminator, saw '"sv, to_sv(*cp), "'"sv);

#if TOML_FINITE_MATH_ONLY
set_error_and_return_default("inf/NaN not allowed when compiled with finite math"sv);
#else
return inf ? (negative ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity())
: std::numeric_limits<double>::quiet_NaN();
#endif
}

TOML_NODISCARD
Expand Down Expand Up @@ -17685,6 +17698,7 @@ TOML_POP_WARNINGS;
#undef TOML_EVAL_BOOL_0
#undef TOML_EVAL_BOOL_1
#undef TOML_EXTERNAL_LINKAGE
#undef TOML_FINITE_MATH_ONLY
#undef TOML_FLAGS_ENUM
#undef TOML_FLOAT_CHARCONV
#undef TOML_FLOAT128
Expand Down

0 comments on commit 785651b

Please sign in to comment.