libstdc++: Redefine __glibcxx_assert to work in C++23 constexpr
commit5e8a30d8b8f4d7ea0a8340b46c1e0c865dbde781
authorJonathan Wakely <jwakely@redhat.com>
Tue, 5 Dec 2023 10:22:17 +0000 (5 10:22 +0000)
committerJonathan Wakely <jwakely@redhat.com>
Tue, 5 Dec 2023 23:33:22 +0000 (5 23:33 +0000)
tree39f8e3ed38235051a45cfef65eda4d27db042433
parent2e7abd09621a4401d44f4513adf126bce4b4828b
libstdc++: Redefine __glibcxx_assert to work in C++23 constexpr

The changes in r14-5979 to support unknown references in constant
expressions caused some test regressions. The way that __glibcxx_assert
is defined for constant evaluation no longer works when
_GLIBCXX_ASSERTIONS is defined.

This change simplifies __glibcxx_assert so that there is only one check,
rather than a constexpr one and a conditionally-enabled runtime one. The
constexpr one does not need to use __builtin_unreachable to cause a
compilation failure, because __glibcxx_assert_fail is not usable in
constant expressions, so that will cause a failure too.

As well as fixing the regressions, this makes the code for the
assertions shorter and simpler, so should be quicker to compile, and
might inline better too.

libstdc++-v3/ChangeLog:

* include/bits/c++config (__glibcxx_assert_fail): Declare even
when assertions are not enabled.
(__glibcxx_constexpr_assert): Remove macro.
(__glibcxx_assert_impl): Remove macro.
(_GLIBCXX_ASSERT_FAIL): New macro.
(_GLIBCXX_DO_ASSERT): New macro.
(__glibcxx_assert): Simplify to a single definition that works
at runtime and during constant evaluation.
* testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc:
Adjust expected errors.
* testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc:
Likewise.
* testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc:
Likewise.
* testsuite/21_strings/basic_string_view/modifiers/remove_prefix/debug.cc:
Likewise.
* testsuite/21_strings/basic_string_view/modifiers/remove_suffix/debug.cc:
Likewise.
* testsuite/23_containers/span/back_neg.cc: Likewise.
* testsuite/23_containers/span/front_neg.cc: Likewise.
* testsuite/23_containers/span/index_op_neg.cc: Likewise.
* testsuite/26_numerics/lcm/105844.cc: Likewise.
13 files changed:
libstdc++-v3/include/bits/c++config
libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/back_constexpr_neg.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/constexpr_neg.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/char/front_constexpr_neg.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/back_constexpr_neg.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/constexpr_neg.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/element_access/wchar_t/front_constexpr_neg.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/modifiers/remove_prefix/debug.cc
libstdc++-v3/testsuite/21_strings/basic_string_view/modifiers/remove_suffix/debug.cc
libstdc++-v3/testsuite/23_containers/span/back_neg.cc
libstdc++-v3/testsuite/23_containers/span/front_neg.cc
libstdc++-v3/testsuite/23_containers/span/index_op_neg.cc
libstdc++-v3/testsuite/26_numerics/lcm/105844.cc