aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2024-11-27 12:28:30 +0000
committerJonathan Wakely <redi@gcc.gnu.org>2024-11-27 21:36:14 +0000
commit73e5d2f87c257c2c12ee72fd4de9bdbb6a8e1aa9 (patch)
treeaec2a9832f4cf9e620bb8077997299fa25291b66
parent17db5742a555d4f8fd5fa324adb6d1e5c55374be (diff)
downloadgcc-73e5d2f87c257c2c12ee72fd4de9bdbb6a8e1aa9.zip
gcc-73e5d2f87c257c2c12ee72fd4de9bdbb6a8e1aa9.tar.gz
gcc-73e5d2f87c257c2c12ee72fd4de9bdbb6a8e1aa9.tar.bz2
libstdc++: Remove __builtin_expect from consteval assertion
libstdc++-v3/ChangeLog: * include/bits/c++config (__glibcxx_assert): Remove useless __builtin_expect from constexpr-only assertion. Improve comments.
-rw-r--r--libstdc++-v3/include/bits/c++config15
1 files changed, 9 insertions, 6 deletions
diff --git a/libstdc++-v3/include/bits/c++config b/libstdc++-v3/include/bits/c++config
index c74b030..a5001d0 100644
--- a/libstdc++-v3/include/bits/c++config
+++ b/libstdc++-v3/include/bits/c++config
@@ -626,14 +626,17 @@ namespace std
#endif
#if defined(_GLIBCXX_ASSERTIONS)
-// Enable runtime assertion checks, and also check in constant expressions.
+// When _GLIBCXX_ASSERTIONS is defined we enable runtime assertion checks.
+// These checks will also be done during constant evaluation.
# define __glibcxx_assert(cond) \
do { \
if (__builtin_expect(!bool(cond), false)) \
_GLIBCXX_ASSERT_FAIL(cond); \
} while (false)
#elif _GLIBCXX_HAVE_IS_CONSTANT_EVALUATED
-// Only check assertions during constant evaluation.
+// _GLIBCXX_ASSERTIONS is not defined, so assertions checks are only enabled
+// during constant evaluation. This ensures we diagnose undefined behaviour
+// in constant expressions.
namespace std
{
__attribute__((__always_inline__,__visibility__("default")))
@@ -643,12 +646,12 @@ namespace std
}
# define __glibcxx_assert(cond) \
do { \
- if (std::__is_constant_evaluated()) \
- if (__builtin_expect(!bool(cond), false)) \
- std::__glibcxx_assert_fail(); \
+ if (std::__is_constant_evaluated() && !bool(cond)) \
+ std::__glibcxx_assert_fail(); \
} while (false)
#else
-// Don't check any assertions.
+// _GLIBCXX_ASSERTIONS is not defined and __is_constant_evaluated() doesn't
+// work so don't check any assertions.
# define __glibcxx_assert(cond)
#endif