diff options
author | Jonathan Wakely <jwakely@redhat.com> | 2020-03-27 23:21:58 +0000 |
---|---|---|
committer | Jonathan Wakely <jwakely@redhat.com> | 2020-03-27 23:26:03 +0000 |
commit | b8a28a06eafafae47ee92fe640b334a8d1e4758a (patch) | |
tree | a475f6510ae977e8029e70663fa91788ba043402 /libstdc++-v3 | |
parent | 81a8d137c22953df2ea046466c62cd26c0dba103 (diff) |
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.
Diffstat (limited to 'libstdc++-v3')
-rw-r--r-- | libstdc++-v3/ChangeLog | 9 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/range_cmp.h | 3 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator.h | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/bits/stl_iterator_base_types.h | 4 | ||||
-rw-r--r-- | libstdc++-v3/include/std/concepts | 2 | ||||
-rw-r--r-- | libstdc++-v3/include/std/version | 7 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc | 15 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc | 9 | ||||
-rw-r--r-- | libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc | 6 |
9 files changed, 37 insertions, 20 deletions
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index fc5f900ed5f..3b96b23ca8f 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -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. diff --git a/libstdc++-v3/include/bits/range_cmp.h b/libstdc++-v3/include/bits/range_cmp.h index 571ba7f9555..0587c599c4b 100644 --- a/libstdc++-v3/include/bits/range_cmp.h +++ b/libstdc++-v3/include/bits/range_cmp.h @@ -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 diff --git a/libstdc++-v3/include/bits/stl_iterator.h b/libstdc++-v3/include/bits/stl_iterator.h index 26eb599993d..e68f66a2b89 100644 --- a/libstdc++-v3/include/bits/stl_iterator.h +++ b/libstdc++-v3/include/bits/stl_iterator.h @@ -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 diff --git a/libstdc++-v3/include/bits/stl_iterator_base_types.h b/libstdc++-v3/include/bits/stl_iterator_base_types.h index 431bf8a62d6..aa02af59dc6 100644 --- a/libstdc++-v3/include/bits/stl_iterator_base_types.h +++ b/libstdc++-v3/include/bits/stl_iterator_base_types.h @@ -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*> diff --git a/libstdc++-v3/include/std/concepts b/libstdc++-v3/include/std/concepts index ba232e953ec..e8ce1adc93a 100644 --- a/libstdc++-v3/include/std/concepts +++ b/libstdc++-v3/include/std/concepts @@ -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 diff --git a/libstdc++-v3/include/std/version b/libstdc++-v3/include/std/version index c6a202e250d..d9a47ee8e8a 100644 --- a/libstdc++-v3/include/std/version +++ b/libstdc++-v3/include/std/version @@ -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 diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc index d64e61e4448..eaf307ddf60 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/move_only.cc @@ -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); } diff --git a/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc b/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc index 8f2d73c520f..4e7b9d01e15 100644 --- a/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc +++ b/libstdc++-v3/testsuite/24_iterators/move_iterator/rel_ops_c++20.cc @@ -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*); diff --git a/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc b/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc index 10ccb35c9e1..dd24730398f 100644 --- a/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc +++ b/libstdc++-v3/testsuite/std/ranges/headers/ranges/synopsis.cc @@ -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; |