]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Fix std::basic_stracktrace to not assume allocators throw std::bad_alloc
authorJonathan Wakely <jwakely@redhat.com>
Tue, 24 Sep 2024 11:44:09 +0000 (12:44 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Mon, 2 Dec 2024 22:41:39 +0000 (22:41 +0000)
The standard allows allocators to throw any kind of exception, not only
something that can be caught as std::bad_alloc. std::basic_stracktrace
was assuming std::bad_alloc.

libstdc++-v3/ChangeLog:

* include/std/stacktrace (basic_stacktrace::_Impl::_M_allocate):
Do not assume allocators only throw std::bad_alloc.

(cherry picked from commit c45844eb7dadcd48e3ce84444a45c270382f7ad1)

libstdc++-v3/include/std/stacktrace

index 962dbed7a41b21655a594c6c53d58afb32b19772..9d05cda85d20f2d80f8d88dfc5e5b5d74739ae7f 100644 (file)
@@ -569,7 +569,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
              if constexpr (is_same_v<allocator_type, allocator<value_type>>)
                {
                  // For std::allocator we use nothrow-new directly so we
-                 // don't need to handle bad_alloc exceptions.
+                 // don't need to handle exceptions from __alloc.allocate(n).
                  size_t __nb = __n * sizeof(value_type);
                  void* const __p = _GLIBCXX_OPERATOR_NEW (__nb, nothrow_t{});
                  if (__p == nullptr) [[unlikely]]
@@ -582,7 +582,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    {
                      _M_frames = __alloc.allocate(__n);
                    }
-                 __catch (const std::bad_alloc&)
+                 __catch (...)
                    {
                      return nullptr;
                    }