public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r11-4480] libstdc++: Add comment to nothrow new explaining catch (...)
@ 2020-10-28 13:19 Jonathan Wakely
  0 siblings, 0 replies; only message in thread
From: Jonathan Wakely @ 2020-10-28 13:19 UTC (permalink / raw)
  To: gcc-cvs, libstdc++-cvs

https://gcc.gnu.org/g:c227d96feb0030d63efad352b8fa7175b4c30721

commit r11-4480-gc227d96feb0030d63efad352b8fa7175b4c30721
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Oct 28 13:19:21 2020 +0000

    libstdc++: Add comment to nothrow new explaining catch (...)
    
    The decision to not rethrow a __forced_unwind exception is deliberate,
    so add a comment explaining it.
    
    libstdc++-v3/ChangeLog:
    
            * libsupc++/new_opnt.cc (new): Add comment about forced unwind
            exceptions.

Diff:
---
 libstdc++-v3/libsupc++/new_opnt.cc | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/libstdc++-v3/libsupc++/new_opnt.cc b/libstdc++-v3/libsupc++/new_opnt.cc
index ace4e6f9345..0e5e39ab994 100644
--- a/libstdc++-v3/libsupc++/new_opnt.cc
+++ b/libstdc++-v3/libsupc++/new_opnt.cc
@@ -26,9 +26,6 @@
 #include <bits/exception_defines.h>
 #include "new"
 
-using std::new_handler;
-using std::bad_alloc;
-
 extern "C" void *malloc (std::size_t);
 
 _GLIBCXX_WEAK_DEFINITION void *
@@ -43,6 +40,13 @@ operator new (std::size_t sz, const std::nothrow_t&) noexcept
     }
   __catch (...)
     {
+      // N.B. catch (...) means the process will terminate if operator new(sz)
+      // exits with a __forced_unwind exception. The process will print
+      // "FATAL: exception not rethrown" to stderr before exiting.
+      //
+      // If we propagated that exception the process would still terminate
+      // (because this function is noexcept) but with a less informative error:
+      // "terminate called without active exception".
       return nullptr;
     }
 }


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-10-28 13:19 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-28 13:19 [gcc r11-4480] libstdc++: Add comment to nothrow new explaining catch (...) Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).