libstdc++: Define __cpp_lib_ranges macro for C++20

Define the feature test macro now that ranges support is complete.

This also changes the preprocessor checks for the __cpp_concepts macro
so that library components depending on concepts are only enabled when
C++20 concepts are supported, and not just for the Concepts TS (which
uses different syntax in places).

	* include/bits/range_cmp.h (__cpp_lib_ranges): Define.
	* include/bits/stl_iterator.h: Check value of __cpp_concepts so that
	C++20 concepts are required.
	* include/bits/stl_iterator_base_types.h: Likewise.
	* include/std/concepts: Likewise.
	* include/std/version: Likewise.
	* testsuite/std/ranges/headers/ranges/synopsis.cc: Check feature test
	macro.
This commit is contained in:
Jonathan Wakely 2020-03-27 23:21:58 +00:00
parent 81a8d137c2
commit b8a28a06ea
9 changed files with 37 additions and 20 deletions

View File

@ -1,5 +1,14 @@
2020-03-27 Jonathan Wakely <jwakely@redhat.com>
* include/bits/range_cmp.h (__cpp_lib_ranges): Define.
* include/bits/stl_iterator.h: Check value of __cpp_concepts so that
C++20 concepts are required.
* include/bits/stl_iterator_base_types.h: Likewise.
* include/std/concepts: Likewise.
* include/std/version: Likewise.
* testsuite/std/ranges/headers/ranges/synopsis.cc: Check feature test
macro.
* include/bits/stl_iterator.h (reverse_iterator::iterator_concept)
(reverse_iterator::iterator_category): Define for C++20.
(reverse_iterator): Define comparison operators correctly for C++20.

View File

@ -55,6 +55,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
};
#ifdef __cpp_lib_concepts
// Define this here, included by all the headers that need to define it.
#define __cpp_lib_ranges 201911L
namespace ranges
{
namespace __detail

View File

@ -214,7 +214,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
*/
_GLIBCXX17_CONSTEXPR pointer
operator->() const
#if __cplusplus > 201703L && defined __cpp_concepts
#if __cplusplus > 201703L && __cpp_concepts >= 201907L
requires is_pointer_v<_Iterator>
|| requires(const _Iterator __i) { __i.operator->(); }
#endif

View File

@ -67,7 +67,7 @@
# include <type_traits> // For __void_t, is_convertible
#endif
#if __cplusplus > 201703L && __cpp_concepts
#if __cplusplus > 201703L && __cpp_concepts >= 201907L
# include <bits/iterator_concepts.h>
#endif
@ -192,7 +192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
#if __cplusplus > 201703L
/// Partial specialization for object pointer types.
template<typename _Tp>
#if __cpp_concepts
#if __cpp_concepts >= 201907L
requires is_object_v<_Tp>
#endif
struct iterator_traits<_Tp*>

View File

@ -30,7 +30,7 @@
#ifndef _GLIBCXX_CONCEPTS
#define _GLIBCXX_CONCEPTS 1
#if __cplusplus > 201703L && __cpp_concepts
#if __cplusplus > 201703L && __cpp_concepts >= 201907L
#pragma GCC system_header

View File

@ -146,6 +146,7 @@
#define __cpp_lib_nonmember_container_access 201411
#define __cpp_lib_not_fn 201603
#define __cpp_lib_optional 201606L
#define __cpp_lib_parallel_algorithm 201603L
#define __cpp_lib_raw_memory_algorithms 201606L
#define __cpp_lib_sample 201603
#ifdef _GLIBCXX_HAS_GTHREADS
@ -158,7 +159,6 @@
#define __cpp_lib_unordered_map_insertion 201411
#define __cpp_lib_unordered_map_try_emplace 201411
#define __cpp_lib_variant 201606L
#define __cpp_lib_parallel_algorithm 201603L
#endif
#if __cplusplus > 201703L
@ -167,7 +167,7 @@
#define __cpp_lib_atomic_value_initialization 201911L
#define __cpp_lib_bitops 201907L
#define __cpp_lib_bounded_array_traits 201902L
#if __cpp_concepts
#if __cpp_concepts >= 201907L
# define __cpp_lib_concepts 201806L
#endif
#if __cpp_impl_destroying_delete
@ -195,6 +195,9 @@
#endif
#define __cpp_lib_list_remove_return_type 201806L
#define __cpp_lib_math_constants 201907L
#if __cpp_lib_concepts
# define __cpp_lib_ranges 201911L
#endif
#define __cpp_lib_span 202002L
#if __cpp_impl_three_way_comparison >= 201907L && __cpp_lib_concepts
# define __cpp_lib_three_way_comparison 201711L

View File

@ -45,16 +45,17 @@ static_assert(std::input_iterator<move_only_iterator>);
template<typename T>
concept has_member_base = requires (T t) { std::forward<T>(t).base(); };
static_assert( ! has_member_base<std::move_iterator<move_iterator>&> );
static_assert( ! has_member_base<const std::move_iterator<move_iterator>&> );
static_assert( has_member_base<std::move_iterator<move_iterator>> );
static_assert( ! has_member_base<const std::move_iterator<move_iterator>> );
using move_only_move_iterator = std::move_iterator<move_only_iterator>;
static_assert( ! has_member_base<move_only_move_iterator&> );
static_assert( ! has_member_base<const move_only_move_iterator&> );
static_assert( has_member_base<move_only_move_iterator> );
static_assert( ! has_member_base<const move_only_move_iterator> );
void
test01()
{
std::move_iterator<move_only_iterator> m1, m2;
m1 = std::make_move_iterator(move_only_iterator{});
move_only_move_iterator m1 = std::make_move_iterator(move_only_iterator{});
move_only_move_iterator m2;
m2 = std::move(m1);
m1.swap(m2);
}

View File

@ -48,15 +48,10 @@ struct Iter
template<int N> friend Iter operator-(Iter<N>, difference_type);
template<int N> friend difference_type operator-(Iter<N>, Iter<N>);
// Define the full set of operators for same-type comparisons
template<int N> friend bool operator==(Iter<N>, Iter<N>); // synthesizes !=
template<int N> friend bool operator<(Iter<N>, Iter<N>);
template<int N> friend bool operator>(Iter<N>, Iter<N>);
template<int N> friend bool operator<=(Iter<N>, Iter<N>);
template<int N> friend bool operator>=(Iter<N>, Iter<N>);
template<int N> friend bool operator==(Iter<N>, Iter<N>);
template<int N> friend std::weak_ordering operator<=>(Iter<N>, Iter<N>);
};
static_assert( std::random_access_iterator<Iter<0>> );
int operator==(Iter<0>, long*);

View File

@ -20,6 +20,12 @@
#include <ranges>
#ifndef __cpp_lib_ranges
# error "Feature test macro for ranges is missing in <ranges>"
#elif __cpp_lib_ranges < 201911L
# error "Feature test macro for ranges has wrong value in <ranges>"
#endif
struct R { };
template<> constexpr bool std::ranges::disable_sized_range<R> = true;