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.
This commit is contained in:
Jonathan Wakely 2020-12-16 13:50:34 +00:00
parent 4be6c4e2a4
commit 96d9670e88
1 changed files with 16 additions and 0 deletions

View File

@ -64,6 +64,10 @@
#endif #endif
#include <ext/alloc_traits.h> #include <ext/alloc_traits.h>
#if !__has_builtin(__builtin_sprintf)
# include <cstdio>
#endif
namespace __gnu_cxx _GLIBCXX_VISIBILITY(default) namespace __gnu_cxx _GLIBCXX_VISIBILITY(default)
{ {
_GLIBCXX_BEGIN_NAMESPACE_VERSION _GLIBCXX_BEGIN_NAMESPACE_VERSION
@ -310,6 +314,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static void static void
log_to_string(std::string& s, const_reference ref) 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]; char buf[40];
const char tab('\t'); const char tab('\t');
s += "label: "; s += "label: ";
@ -332,6 +340,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static void static void
log_to_string(std::string& s, const std::pair<const void*, size_t>& ref) 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]; char buf[40];
const char tab('\t'); const char tab('\t');
s += "label: "; s += "label: ";
@ -566,6 +578,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
static gen_t generator(engine(), distribution); static gen_t generator(engine(), distribution);
#endif #endif
#if ! __has_builtin(__builtin_sprintf)
__typeof__(&std::sprintf) __builtin_sprintf = &std::sprintf;
#endif
double random = generator(); double random = generator();
if (random < distribution.min() || random > distribution.max()) if (random < distribution.min() || random > distribution.max())
{ {