public inbox for libstdc++-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jonathan Wakely <redi@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org
Subject: [gcc r12-2326] libstdc++: Add noexcept to __replacement_assert [PR101429]
Date: Thu, 15 Jul 2021 15:25:56 +0000 (GMT)	[thread overview]
Message-ID: <20210715152556.153363985030@sourceware.org> (raw)

https://gcc.gnu.org/g:1f7182d68c24985dace2a94422c671ff987c262c

commit r12-2326-g1f7182d68c24985dace2a94422c671ff987c262c
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Jul 14 12:25:11 2021 +0100

    libstdc++: Add noexcept to __replacement_assert [PR101429]
    
    This results in slightly smaller code when assertions are enabled when
    either using Clang (because it adds code to call std::terminate when
    potentially-throwing functions are called in a noexcept function) or a
    freestanding or non-verbose build (because it doesn't use printf).
    
    Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
    
    libstdc++-v3/ChangeLog:
    
            PR libstdc++/101429
            * include/bits/c++config (__replacement_assert): Add noexcept.
            [!_GLIBCXX_VERBOSE] (__glibcxx_assert_impl): Use __builtin_trap
            instead of __replacement_assert.

Diff:
---
 libstdc++-v3/include/bits/c++config | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index 9314117aed8..69ace386dd7 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -500,6 +500,7 @@ namespace std
 // Assert.
 #if defined(_GLIBCXX_ASSERTIONS) \
   || defined(_GLIBCXX_PARALLEL) || defined(_GLIBCXX_PARALLEL_ASSERTIONS)
+# if _GLIBCXX_HOSTED && _GLIBCXX_VERBOSE
 namespace std
 {
   // Avoid the use of assert, because we're trying to keep the <cassert>
@@ -508,6 +509,7 @@ namespace std
   inline void
   __replacement_assert(const char* __file, int __line,
 		       const char* __function, const char* __condition)
+  _GLIBCXX_NOEXCEPT
   {
     __builtin_printf("%s:%d: %s: Assertion '%s' failed.\n", __file, __line,
 		     __function, __condition);
@@ -517,10 +519,18 @@ namespace std
 #define __glibcxx_assert_impl(_Condition)			       \
   if (__builtin_expect(!bool(_Condition), false))		       \
   {								       \
-    __glibcxx_constexpr_assert(_Condition);			       \
+    __glibcxx_constexpr_assert(false);				       \
     std::__replacement_assert(__FILE__, __LINE__, __PRETTY_FUNCTION__, \
 			      #_Condition);			       \
   }
+# else // ! VERBOSE
+# define __glibcxx_assert_impl(_Condition)		\
+  if (__builtin_expect(!bool(_Condition), false))	\
+  {							\
+    __glibcxx_constexpr_assert(false);			\
+    __builtin_abort();					\
+  }
+#endif
 #endif
 
 #if defined(_GLIBCXX_ASSERTIONS)


                 reply	other threads:[~2021-07-15 15:25 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210715152556.153363985030@sourceware.org \
    --to=redi@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    --cc=libstdc++-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).