aboutsummaryrefslogtreecommitdiff
path: root/gcc/function.cc
diff options
context:
space:
mode:
authorJonathan Wakely <jwakely@redhat.com>2022-04-01 12:25:02 +0100
committerJonathan Wakely <jwakely@redhat.com>2022-04-01 13:17:18 +0100
commitbabaabbcc8346758be0051b32272da18d54f5eea (patch)
tree1a63a98ad862f3fa05fd8e12882a37795f4db7ce /gcc/function.cc
parent944da70a5d1cdc5bd4327b2d32420f57b6883985 (diff)
downloadgcc-babaabbcc8346758be0051b32272da18d54f5eea.zip
gcc-babaabbcc8346758be0051b32272da18d54f5eea.tar.gz
gcc-babaabbcc8346758be0051b32272da18d54f5eea.tar.bz2
libstdc++: Implement std::unreachable() for C++23 (P0627R6)
This defines std::unreachable as an assertion for debug mode, a trap when _GLIBCXX_ASSERTIONS is defined, and __builtin_unreachable() otherwise. The reason for only using __builtin_trap() in the second case is to avoid the overhead of setting up a call to __glibcxx_assert_fail that should never happen. UBsan can detect if __builtin_unreachable() is executed, so if a feature test macro for that sanitizer is added, we could change just use __builtin_unreachable() when the sanitizer is enabled. While thinking about what the debug assertion failure should print, I noticed that the __glibcxx_assert_fail function doesn't check for null pointers. This adds a check so we don't try to print them if null. libstdc++-v3/ChangeLog: * include/std/utility (unreachable): Define for C++23. * include/std/version (__cpp_lib_unreachable): Define. * src/c++11/debug.cc (__glibcxx_assert_fail): Check for valid arguments. Handle only the function being given. * testsuite/20_util/unreachable/1.cc: New test. * testsuite/20_util/unreachable/version.cc: New test.
Diffstat (limited to 'gcc/function.cc')
0 files changed, 0 insertions, 0 deletions