From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2136) id F40D13A15818; Wed, 17 Jun 2020 20:01:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F40D13A15818 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1592424066; bh=EcPlGXXQmDnOvFpCcmSdXtemPxyom8U0ASQKOgYh9/A=; h=From:To:Subject:Date:From; b=cwW2G81Pk2uuzok0P32ZrOqAC87jEAzztdMhaTsw++B4FqXUC7VIrJVUbIXNbB9q8 NfnCIE7jQerRJQOsL2QIOtVHE0CsqeqYRabOnUqxvW8OkgluG9M7SGC4+VBRiJ0Jzu NdxDSUeYunHoShGAbuBLW5/wpLh+lcRuz74/65Fg= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Aldy Hernandez To: gcc-cvs@gcc.gnu.org, libstdc++-cvs@gcc.gnu.org Subject: [gcc/devel/ranger] libstdc++: Define __cpp_lib_ranges macro for C++20 X-Act-Checkin: gcc X-Git-Author: Jonathan Wakely X-Git-Refname: refs/heads/devel/ranger X-Git-Oldrev: 81a8d137c22953df2ea046466c62cd26c0dba103 X-Git-Newrev: b8a28a06eafafae47ee92fe640b334a8d1e4758a Message-Id: <20200617200105.F40D13A15818@sourceware.org> Date: Wed, 17 Jun 2020 20:01:05 +0000 (GMT) X-BeenThere: libstdc++-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 17 Jun 2020 20:01:06 -0000 https://gcc.gnu.org/g:b8a28a06eafafae47ee92fe640b334a8d1e4758a commit b8a28a06eafafae47ee92fe640b334a8d1e4758a Author: Jonathan Wakely Date: Fri Mar 27 23:21:58 2020 +0000 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. Diff: --- libstdc++-v3/ChangeLog | 9 +++++++++ libstdc++-v3/include/bits/range_cmp.h | 3 +++ libstdc++-v3/include/bits/stl_iterator.h | 2 +- libstdc++-v3/include/bits/stl_iterator_base_types.h | 4 ++-- libstdc++-v3/include/std/concepts | 2 +- libstdc++-v3/include/std/version | 7 +++++-- .../testsuite/24_iterators/move_iterator/move_only.cc | 15 ++++++++------- .../testsuite/24_iterators/move_iterator/rel_ops_c++20.cc | 9 ++------- .../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 + * 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 // For __void_t, is_convertible #endif -#if __cplusplus > 201703L && __cpp_concepts +#if __cplusplus > 201703L && __cpp_concepts >= 201907L # include #endif @@ -192,7 +192,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cplusplus > 201703L /// Partial specialization for object pointer types. template -#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); template concept has_member_base = requires (T t) { std::forward(t).base(); }; -static_assert( ! has_member_base&> ); -static_assert( ! has_member_base&> ); -static_assert( has_member_base> ); -static_assert( ! has_member_base> ); +using move_only_move_iterator = std::move_iterator; + +static_assert( ! has_member_base ); +static_assert( ! has_member_base ); +static_assert( has_member_base ); +static_assert( ! has_member_base ); void test01() { - std::move_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 friend Iter operator-(Iter, difference_type); template friend difference_type operator-(Iter, Iter); - // Define the full set of operators for same-type comparisons - template friend bool operator==(Iter, Iter); // synthesizes != - template friend bool operator<(Iter, Iter); - template friend bool operator>(Iter, Iter); - template friend bool operator<=(Iter, Iter); - template friend bool operator>=(Iter, Iter); + template friend bool operator==(Iter, Iter); + template friend std::weak_ordering operator<=>(Iter, Iter); }; - static_assert( std::random_access_iterator> ); 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 +#ifndef __cpp_lib_ranges +# error "Feature test macro for ranges is missing in " +#elif __cpp_lib_ranges < 201911L +# error "Feature test macro for ranges has wrong value in " +#endif + struct R { }; template<> constexpr bool std::ranges::disable_sized_range = true;