]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Simplify __throw_out_of_range_fmt for freestanding
authorJonathan Wakely <jwakely@redhat.com>
Thu, 20 May 2021 17:13:00 +0000 (18:13 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 1 Oct 2021 19:36:54 +0000 (20:36 +0100)
There is no point expanding the format string if we're just going to
abort instead of throw an exception. And for freestanding or non-verbose
builds we shouldn't do it either, to reduce the binary size.

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
libstdc++-v3/ChangeLog:

* src/c++11/functexcept.cc (__throw_out_of_range_fmt): Do not
expand the format string for freestanding, or non-vebose, or if
we're just going to abort anyway.
* src/c++11/snprintf_lite.cc: Remove unused header and
declaration.

libstdc++-v3/src/c++11/functexcept.cc
libstdc++-v3/src/c++11/snprintf_lite.cc

index 6f0071391c734b3fa6dd464f4fb2a0dc36dddb43..d1570b69f15b10d8c4b3ea8cf0fc4fc70391b560 100644 (file)
@@ -88,6 +88,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
   void
   __throw_out_of_range_fmt(const char* __fmt, ...)
   {
+#if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE && __cpp_exceptions
     const size_t __len = __builtin_strlen(__fmt);
     // We expect at most 2 numbers, and 1 short string. The additional
     // 512 bytes should provide more than enough space for expansion.
@@ -96,9 +97,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     va_list __ap;
 
     va_start(__ap, __fmt);
-    __gnu_cxx::__snprintf_lite(__s, __alloca_size, __fmt, __ap);
-    _GLIBCXX_THROW_OR_ABORT(out_of_range(_(__s)));
+    __gnu_cxx::__snprintf_lite(__s, __alloca_size, _(__fmt), __ap);
+    throw out_of_range(__s);
     va_end(__ap);  // Not reached.
+#else
+    __throw_out_of_range(__fmt);
+#endif
   }
 
   void
index dcf8421cac26f16947e37aa62edb8c060bef9cd5..ffeb7bf64c0137e8f1072b523547f0ac49201162 100644 (file)
 // <http://www.gnu.org/licenses/>.
 
 #include <stdarg.h>
+#include <stddef.h>
 #include <bits/functexcept.h>
-#include <bits/locale_facets.h>
-
-namespace std {
-_GLIBCXX_BEGIN_NAMESPACE_VERSION
-  template<typename _CharT, typename _ValueT>
-  int
-  __int_to_char(_CharT* __bufend, _ValueT __v, const _CharT* __lit,
-                ios_base::fmtflags __flags, bool __dec);
-_GLIBCXX_END_NAMESPACE_VERSION
-}
 
 namespace __gnu_cxx {