aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2020-12-16 13:50:34 +0000
committerJonathan Wakely <jwakely@redhat.com>2020-12-16 14:33:26 +0000
commit96d9670e88333d8896a5d2f2bb0403c1e2ad19ab (patch)
tree8dc573d2011f42b250297cee152fdaf9c9869c9f
parent4be6c4e2a4df5229ec4545e7244dfcdbf1f5bca1 (diff)
downloadgcc-96d9670e88333d8896a5d2f2bb0403c1e2ad19ab.zip
gcc-96d9670e88333d8896a5d2f2bb0403c1e2ad19ab.tar.gz
gcc-96d9670e88333d8896a5d2f2bb0403c1e2ad19ab.tar.bz2
libstdc++: Only use __builtin_sprintf if supported [PR 96083]
Clang doesn't support __builtin_sprintf, so use std::sprintf instead. libstdc++-v3/ChangeLog: PR libstdc++/96083 * include/ext/throw_allocator.h: Use __has_builtin to check for __builtin_sprintf support, and use std::sprtinf if necessary.
-rw-r--r--libstdc++-v3/include/ext/throw_allocator.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h
index 0ab174f..2364827 100644
--- a/libstdc++-v3/include/ext/throw_allocator.h
+++ b/libstdc++-v3/include/ext/throw_allocator.h
@@ -64,6 +64,10 @@
#endif
#include <ext/alloc_traits.h>
+#if !__has_builtin(__builtin_sprintf)
+# include <cstdio>
+#endif
+
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
{
_GLIBCXX_BEGIN_NAMESPACE_VERSION
@@ -310,6 +314,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static void
log_to_string(std::string& s, const_reference ref)
{
+#if ! __has_builtin(__builtin_sprintf)
+ __typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
+#endif
+
char buf[40];
const char tab('\t');
s += "label: ";
@@ -332,6 +340,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static void
log_to_string(std::string& s, const std::pair<const void*, size_t>& ref)
{
+#if ! __has_builtin(__builtin_sprintf)
+ auto __builtin_sprintf = &std::sprintf;
+#endif
+
char buf[40];
const char tab('\t');
s += "label: ";
@@ -566,6 +578,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static gen_t generator(engine(), distribution);
#endif
+#if ! __has_builtin(__builtin_sprintf)
+ __typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
+#endif
+
double random = generator();
if (random < distribution.min() || random > distribution.max())
{