From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2181) id 760253854810; Wed, 16 Dec 2020 14:33:46 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 760253854810 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jonathan Wakely To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc r11-6146] libstdc++: Only use __builtin_sprintf if supported [PR 96083] X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/master X-Git-Oldrev: 4be6c4e2a4df5229ec4545e7244dfcdbf1f5bca1 X-Git-Newrev: 96d9670e88333d8896a5d2f2bb0403c1e2ad19ab Message-Id: <20201216143346.760253854810@sourceware.org> Date: Wed, 16 Dec 2020 14:33:46 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Dec 2020 14:33:46 -0000 https://gcc.gnu.org/g:96d9670e88333d8896a5d2f2bb0403c1e2ad19ab commit r11-6146-g96d9670e88333d8896a5d2f2bb0403c1e2ad19ab Author: Jonathan Wakely Date: Wed Dec 16 13:50:34 2020 +0000 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. Diff: --- libstdc++-v3/include/ext/throw_allocator.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h index 0ab174f19a5..2364827a632 100644 --- a/libstdc++-v3/include/ext/throw_allocator.h +++ b/libstdc++-v3/include/ext/throw_allocator.h @@ -64,6 +64,10 @@ #endif #include +#if !__has_builtin(__builtin_sprintf) +# include +#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& 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()) {