[libc++] Improve the implementation of std::unreachable
authorLouis Dionne <ldionne.2@gmail.com>
Wed, 10 Aug 2022 21:27:00 +0000 (17:27 -0400)
committerLouis Dionne <ldionne.2@gmail.com>
Wed, 11 Jan 2023 15:15:25 +0000 (10:15 -0500)
commit678dd9a589d62159c76886d22fa9ccbd1222e1f2
tree841d3d0c333569ad139e8a87fc4399a867b5ee8c
parentf0e60f99aefff66ca6223eb3c3a36615f36454ec
[libc++] Improve the implementation of std::unreachable

First, use __builtin_unreachable unconditionally. It is implemented by
all the compilers that we support. Clang started supporting it around
Clang 4, and GCC around GCC 4.10.

Also add _LIBCPP_ASSERT so that we will actually get a guaranteed crash
if we reached `std::unreachable()` and assertions have been enabled,
since that's UB that's extremely easy to catch.

Differential Revision: https://reviews.llvm.org/D131620
libcxx/include/__utility/unreachable.h
libcxx/include/utility
libcxx/test/libcxx/transitive_includes/cxx2b.csv
libcxx/test/std/utilities/utility/utility.unreachable/assert.unreachable.pass.cpp [new file with mode: 0644]
libcxx/test/std/utilities/utility/utility.unreachable/unreachable.pass.cpp [moved from libcxx/test/std/utilities/utility/utility.unreachable/unreachable.compile.pass.cpp with 53% similarity]