libstdc++: Simplify C++20 poison pill overloads (P2602R2)

This implements the C++23 change "Poison Pills are Too Toxic". This
makes sense to do unconditionally for C++20, as the corner cases that it
fixes are considered to be defects in the C++20 design (e.g. LWG3480 was
needed to fix directory iterators because of these pills being too
toxic).

libstdc++-v3/ChangeLog:

	* include/bits/iterator_concepts.h (__imove::iter_move): Define
	poison pill as deleted for consistency.
	(__access::begin): Replace with a single declaration.
	* include/bits/ranges_base.h (__access::end, __access::rbegin)
	(__access::rend, __access::size): Likewise.
	* include/bits/version.def (ranges): Update value for C++23.
	* include/bits/version.h: Regenerate.
	* libsupc++/compare (__compare): Add missing poison pill
	overloads.
	* testsuite/std/ranges/version_c++23.cc: Adjust expected value
	of __cpp_lib_ranges.
	* testsuite/std/ranges/access/p2602.cc: New test.
This commit is contained in:
Jonathan Wakely 2023-09-06 13:36:02 +01:00
parent faea9d92db
commit 6854e3ac71
7 changed files with 49 additions and 17 deletions

View File

@ -100,7 +100,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
/// @cond undocumented
namespace __imove
{
void iter_move();
void iter_move() = delete;
template<typename _Tp>
concept __adl_imove
@ -979,9 +979,8 @@ namespace ranges
{ __decay_copy(__t.begin()) } -> input_or_output_iterator;
};
// Poison pills so that unqualified lookup doesn't find std::begin.
void begin(auto&) = delete;
void begin(const auto&) = delete;
// Poison pill so that unqualified lookup doesn't find std::begin.
void begin() = delete;
template<typename _Tp>
concept __adl_begin = __class_or_enum<remove_reference_t<_Tp>>

View File

@ -133,9 +133,8 @@ namespace ranges
{ __decay_copy(__t.end()) } -> sentinel_for<__range_iter_t<_Tp>>;
};
// Poison pills so that unqualified lookup doesn't find std::end.
void end(auto&) = delete;
void end(const auto&) = delete;
// Poison pill so that unqualified lookup doesn't find std::end.
void end() = delete;
template<typename _Tp>
concept __adl_end = __class_or_enum<remove_reference_t<_Tp>>
@ -184,8 +183,7 @@ namespace ranges
{ __decay_copy(__t.rbegin()) } -> input_or_output_iterator;
};
void rbegin(auto&) = delete;
void rbegin(const auto&) = delete;
void rbegin() = delete;
template<typename _Tp>
concept __adl_rbegin = __class_or_enum<remove_reference_t<_Tp>>
@ -248,8 +246,7 @@ namespace ranges
-> sentinel_for<decltype(_RBegin{}(std::forward<_Tp>(__t)))>;
};
void rend(auto&) = delete;
void rend(const auto&) = delete;
void rend() = delete;
template<typename _Tp>
concept __adl_rend = __class_or_enum<remove_reference_t<_Tp>>
@ -306,8 +303,7 @@ namespace ranges
{ __decay_copy(__t.size()) } -> __detail::__is_integer_like;
};
void size(auto&) = delete;
void size(const auto&) = delete;
void size() = delete;
template<typename _Tp>
concept __adl_size = __class_or_enum<remove_reference_t<_Tp>>

View File

@ -1045,7 +1045,7 @@ ftms = {
ftms = {
name = ranges;
values = {
v = 202207;
v = 202211;
cxxmin = 23;
extra_cond = "__glibcxx_concepts";
};

View File

@ -1290,9 +1290,9 @@
// from version.def line 1046
#if !defined(__cpp_lib_ranges)
# if (__cplusplus >= 202302L) && (__glibcxx_concepts)
# define __glibcxx_ranges 202207L
# define __glibcxx_ranges 202211L
# if defined(__glibcxx_want_all) || defined(__glibcxx_want_ranges)
# define __cpp_lib_ranges 202207L
# define __cpp_lib_ranges 202211L
# endif
# elif (__cplusplus >= 202002L) && (__glibcxx_concepts)
# define __glibcxx_ranges 202110L

View File

@ -612,6 +612,8 @@ namespace std _GLIBCXX_VISIBILITY(default)
}
}
void strong_order() = delete;
template<typename _Tp, typename _Up>
concept __adl_strong = requires(_Tp&& __t, _Up&& __u)
{
@ -619,6 +621,8 @@ namespace std _GLIBCXX_VISIBILITY(default)
static_cast<_Up&&>(__u)));
};
void weak_order() = delete;
template<typename _Tp, typename _Up>
concept __adl_weak = requires(_Tp&& __t, _Up&& __u)
{
@ -626,6 +630,8 @@ namespace std _GLIBCXX_VISIBILITY(default)
static_cast<_Up&&>(__u)));
};
void partial_order() = delete;
template<typename _Tp, typename _Up>
concept __adl_partial = requires(_Tp&& __t, _Up&& __u)
{

View File

@ -0,0 +1,31 @@
// { dg-options "-std=gnu++20" }
// { dg-do compile { target c++20 } }
// P2602R2 Poison Pills are Too Toxic
#include <ranges>
struct A {
friend auto begin(A const&) -> int const*;
friend auto end(A const&) -> int const*;
};
struct B {
friend auto begin(B&) -> int*;
friend auto end(B&) -> int*;
};
static_assert( std::ranges::range<A> );
static_assert( std::ranges::range<const A> );
static_assert( std::ranges::range<B> );
static_assert( ! std::ranges::range<const B> );
class Test {
friend size_t size(const Test&) {
return 0;
}
};
size_t f(Test t) {
return std::ranges::size(t);
}

View File

@ -4,7 +4,7 @@
#include <version>
#if __STDC_HOSTED__
# if __cpp_lib_ranges != 202207L
# if __cpp_lib_ranges != 202211L
# error "Feature-test macro __cpp_lib_ranges has wrong value in <version>"
# endif
#endif