summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Altmanninger <aclopte@gmail.com>2022-05-08 13:41:30 +0200
committerJohannes Altmanninger <aclopte@gmail.com>2022-05-08 14:00:27 +0200
commit987e367955f263059715ad16c8fbbb57b434ce23 (patch)
treec8d59fa916931fd9b448b3ace5d9103df0204352
parent56c3ab4ff86798aaf4f79d3d1a92041d05d202d6 (diff)
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
-rw-r--r--src/string_utils.cc6
1 files changed, 6 insertions, 0 deletions
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)