diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2023-12-06 13:39:52 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2023-12-14 16:07:48 +0000 |
commit | 7d00a59229ee17af009a3c6c6208b0611740ed49 (patch) | |
tree | 63bdd05fd14060189f9feba929f11e38fd4652ea /libstdc++-v3/testsuite/23_containers | |
parent | 4e9b2c94e45f5991a472fb639fb2baa6aa42b76b (diff) | |
download | gcc-7d00a59229ee17af009a3c6c6208b0611740ed49.zip gcc-7d00a59229ee17af009a3c6c6208b0611740ed49.tar.gz gcc-7d00a59229ee17af009a3c6c6208b0611740ed49.tar.bz2 |
libstdc++: Make __gnu_debug::vector usable in constant expressions [PR109536]
This makes constexpr std::vector (mostly) work in Debug Mode. All safe
iterator instrumentation and checking is disabled during constant
evaluation, because it requires mutex locks and calls to non-inline
functions defined in libstdc++.so. It should be OK to disable the safety
checks, because most UB should be detected during constant evaluation
anyway.
We could try to enable the full checking in constexpr, but it would mean
wrapping all the non-inline functions like _M_attach with an inline
_M_constexpr_attach that does the iterator housekeeping inline without
mutex locks when called for constant evaluation, and calls the
non-inline function at runtime. That could be done in future if we find
that we've lost safety or useful checking by disabling the safe
iterators.
There are a few test failures in C++20 mode, which I'm unable to
explain. The _Safe_iterator::operator++() member gives errors for using
non-constexpr functions during constant evaluation, even though those
functions are guarded by std::is_constant_evaluated() checks. The same
code works fine for C++23 and up.
libstdc++-v3/ChangeLog:
PR libstdc++/109536
* include/bits/c++config (__glibcxx_constexpr_assert): Remove
macro.
* include/bits/stl_algobase.h (__niter_base, __copy_move_a)
(__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux)
(__lexicographical_compare_aux): Add constexpr to overloads for
debug mode iterators.
* include/debug/helper_functions.h (__unsafe): Add constexpr.
* include/debug/macros.h (_GLIBCXX_DEBUG_VERIFY_COND_AT): Remove
macro, folding it into ...
(_GLIBCXX_DEBUG_VERIFY_AT_F): ... here. Do not use
__glibcxx_constexpr_assert.
* include/debug/safe_base.h (_Safe_iterator_base): Add constexpr
to some member functions. Omit attaching, detaching and checking
operations during constant evaluation.
* include/debug/safe_container.h (_Safe_container): Likewise.
* include/debug/safe_iterator.h (_Safe_iterator): Likewise.
* include/debug/safe_iterator.tcc (__niter_base, __copy_move_a)
(__copy_move_backward_a, __fill_a, __fill_n_a, __equal_aux)
(__lexicographical_compare_aux): Add constexpr.
* include/debug/vector (_Safe_vector, vector): Add constexpr.
Omit safe iterator operations during constant evaluation.
* testsuite/23_containers/vector/bool/capacity/constexpr.cc:
Remove dg-xfail-if for debug mode.
* testsuite/23_containers/vector/bool/cmp_c++20.cc: Likewise.
* testsuite/23_containers/vector/bool/cons/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/element_access/1.cc:
Likewise.
* testsuite/23_containers/vector/bool/element_access/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/capacity/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/cmp_c++20.cc: Likewise.
* testsuite/23_containers/vector/cons/constexpr.cc: Likewise.
* testsuite/23_containers/vector/data_access/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/element_access/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/assign/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/modifiers/swap/constexpr.cc:
Likewise.
* testsuite/23_containers/vector/cons/destructible_debug_neg.cc:
Adjust dg-error line number.
Diffstat (limited to 'libstdc++-v3/testsuite/23_containers')
17 files changed, 3 insertions, 17 deletions
diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/constexpr.cc index d44e9d9..534128c 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/capacity/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cmp_c++20.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cmp_c++20.cc index 66197e0..e852c38 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/cmp_c++20.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/cmp_c++20.cc @@ -16,7 +16,6 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/constexpr.cc index 0e0c1e1..88d99fe 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/cons/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/cons/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc index 2a43084..e7d7108 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/1.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++23 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc index 5b8ca94..d6b657e 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/element_access/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc index 3ad7dda..31a6793 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/assign/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/constexpr.cc index 22a4df5..0e37f9a 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc index 624ff96..d2a0218 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/bool/modifiers/swap/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <utility> @@ -49,6 +48,7 @@ test_member_swap() static_assert(test_member_swap()); +#ifndef _GLIBCXX_DEBUG constexpr bool test_reference_swap() { @@ -63,3 +63,4 @@ test_reference_swap() } static_assert(test_reference_swap()); +#endif diff --git a/libstdc++-v3/testsuite/23_containers/vector/capacity/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/capacity/constexpr.cc index 018a479..c331dbd 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/capacity/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/capacity/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/cmp_c++20.cc b/libstdc++-v3/testsuite/23_containers/vector/cmp_c++20.cc index 72c5c6c..63cb92c0 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/cmp_c++20.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/cmp_c++20.cc @@ -16,7 +16,6 @@ // <http://www.gnu.org/licenses/>. // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/constexpr.cc index 7bf8651..fa78676 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/cons/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/constexpr.cc @@ -1,6 +1,5 @@ // { dg-do compile { target c++20 } } // { dg-add-options no_pch } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> diff --git a/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc b/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc index 55b9b53..31d6f95 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/cons/destructible_debug_neg.cc @@ -46,7 +46,7 @@ test02() // { dg-error "value type is destructible" "" { target *-*-* } 0 } // In Debug Mode the "required from here" errors come from <debug/vector> -// { dg-error "required from here" "" { target *-*-* } 172 } +// { dg-error "required from here" "" { target *-*-* } 180 } // Needed because of PR c++/92193 // { dg-prune-output "deleted function" } diff --git a/libstdc++-v3/testsuite/23_containers/vector/data_access/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/data_access/constexpr.cc index f5b601a..142050e 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/data_access/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/data_access/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/element_access/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/element_access/constexpr.cc index 60c66dc..ee93d2f 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/element_access/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/element_access/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/constexpr.cc index cca20f4..41fc8d9 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/assign/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/constexpr.cc index 766e3a7..4aa1f1f 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <testsuite_hooks.h> diff --git a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/constexpr.cc b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/constexpr.cc index 45b3986..77d2a51 100644 --- a/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/constexpr.cc +++ b/libstdc++-v3/testsuite/23_containers/vector/modifiers/swap/constexpr.cc @@ -1,5 +1,4 @@ // { dg-do compile { target c++20 } } -// { dg-xfail-if "not supported" { debug_mode } } #include <vector> #include <utility> |