From 987e367955f263059715ad16c8fbbb57b434ce23 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Sun, 8 May 2022 13:41:30 +0200 Subject: [PATCH] Work around incomplete std::to_chars() support in libstdc++ 10 Ubuntu 20.04 ships GCC's libstdc++ 10 from 2020 which implements std::to_chars() for integers but not for floats. Use the float overload only if the library advertises support via the feature testing macro. This can be removed once we require GCC 11 (see https://www.gnu.org/software/gcc/gcc-11/changes.html). Closes #4607 --- src/string_utils.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/string_utils.cc b/src/string_utils.cc index 0b0c113c..39205d7e 100644 --- a/src/string_utils.cc +++ b/src/string_utils.cc @@ -197,7 +197,13 @@ InplaceString<23> to_string(Hex val) InplaceString<23> to_string(float val) { +#if defined(__cpp_lib_to_chars) return to_string_impl<23>(val, std::chars_format::general); +#else + InplaceString<23> res; + res.m_length = sprintf(res.m_data, "%f", val); + return res; +#endif } InplaceString<7> to_string(Codepoint c)