From 3841739c29a54c0141c3156cdd47891c258b2b88 Mon Sep 17 00:00:00 2001 From: Jonathan Wakely Date: Mon, 24 Feb 2020 11:45:20 +0000 Subject: [PATCH] libstdc++: enable_view has false positives (LWG 3326) * include/std/ranges (__deep_const_range, __enable_view_impl): Remove. (ranges::enable_view): Simplify (LWG 3326). * include/bits/range_access.h (ranges::enable_view): Declare. * include/bits/regex.h (__enable_view_impl): Remove partial specialization. * include/bits/stl_multiset.h (__enable_view_impl): Likewise. * include/bits/stl_set.h (__enable_view_impl): Likewise. * include/bits/unordered_set.h (__enable_view_impl): Likewise. * include/debug/multiset.h (__enable_view_impl): Likewise. * include/debug/set.h (__enable_view_impl): Likewise. * include/debug/unordered_set (__enable_view_impl): Likewise. * include/experimental/string_view (ranges::enable_view): Define partial specialization. * include/std/span (ranges::enable_view): Likewise. * include/std/string_view (ranges::enable_view): Likewise. * testsuite/std/ranges/view.cc: Check satisfaction of updated concept. --- libstdc++-v3/ChangeLog | 19 +++++++++++++++++++ libstdc++-v3/include/bits/range_access.h | 3 +++ libstdc++-v3/include/bits/regex.h | 10 ---------- libstdc++-v3/include/bits/stl_multiset.h | 11 ----------- libstdc++-v3/include/bits/stl_set.h | 9 --------- libstdc++-v3/include/bits/unordered_set.h | 15 --------------- libstdc++-v3/include/debug/multiset.h | 13 ------------- libstdc++-v3/include/debug/set.h | 12 ------------ libstdc++-v3/include/debug/unordered_set | 16 ---------------- libstdc++-v3/include/experimental/string_view | 6 +++++- libstdc++-v3/include/std/ranges | 19 +------------------ libstdc++-v3/include/std/span | 7 ++++++- libstdc++-v3/include/std/string_view | 6 +++++- libstdc++-v3/testsuite/std/ranges/view.cc | 12 +++++++++++- 14 files changed, 50 insertions(+), 108 deletions(-) diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog index 7e065ef3e1d..457afdbadc8 100644 --- a/libstdc++-v3/ChangeLog +++ b/libstdc++-v3/ChangeLog @@ -1,3 +1,22 @@ +2020-02-24 Jonathan Wakely + + * include/std/ranges (__deep_const_range, __enable_view_impl): Remove. + (ranges::enable_view): Simplify (LWG 3326). + * include/bits/range_access.h (ranges::enable_view): Declare. + * include/bits/regex.h (__enable_view_impl): Remove partial + specialization. + * include/bits/stl_multiset.h (__enable_view_impl): Likewise. + * include/bits/stl_set.h (__enable_view_impl): Likewise. + * include/bits/unordered_set.h (__enable_view_impl): Likewise. + * include/debug/multiset.h (__enable_view_impl): Likewise. + * include/debug/set.h (__enable_view_impl): Likewise. + * include/debug/unordered_set (__enable_view_impl): Likewise. + * include/experimental/string_view (ranges::enable_view): Define + partial specialization. + * include/std/span (ranges::enable_view): Likewise. + * include/std/string_view (ranges::enable_view): Likewise. + * testsuite/std/ranges/view.cc: Check satisfaction of updated concept. + 2020-02-21 Jonathan Wakely * include/std/optional (operator<=>(optional, optional)) diff --git a/libstdc++-v3/include/bits/range_access.h b/libstdc++-v3/include/bits/range_access.h index eb91ade35ff..8b276fd6625 100644 --- a/libstdc++-v3/include/bits/range_access.h +++ b/libstdc++-v3/include/bits/range_access.h @@ -346,6 +346,9 @@ namespace ranges template inline constexpr bool enable_borrowed_range = false; + template + extern const bool enable_view; + namespace __detail { template diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h index 3307e1c917c..dcae83eea4e 100644 --- a/libstdc++-v3/include/bits/regex.h +++ b/libstdc++-v3/include/bits/regex.h @@ -2058,16 +2058,6 @@ _GLIBCXX_BEGIN_NAMESPACE_CXX11 _GLIBCXX_END_NAMESPACE_CXX11 -#if __cplusplus > 201703L -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool __enable_view_impl> - = false; -} // namespace ranges::__detail -#endif // C++20 - // [28.11.2] Function template regex_match /** * @name Matching, Searching, and Replacing diff --git a/libstdc++-v3/include/bits/stl_multiset.h b/libstdc++-v3/include/bits/stl_multiset.h index b8b82912c91..ab62df1e508 100644 --- a/libstdc++-v3/include/bits/stl_multiset.h +++ b/libstdc++-v3/include/bits/stl_multiset.h @@ -1038,17 +1038,6 @@ _GLIBCXX_END_NAMESPACE_CONTAINER _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set) { return __set._M_t; } }; - -#if __cplusplus > 201703L -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool - __enable_view_impl<_GLIBCXX_STD_C::multiset<_Key, _Compare, _Alloc>> - = false; -} // namespace ranges::__detail -#endif // C++20 #endif // C++17 _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/stl_set.h b/libstdc++-v3/include/bits/stl_set.h index 5f3e78dc470..4f8d631bb3b 100644 --- a/libstdc++-v3/include/bits/stl_set.h +++ b/libstdc++-v3/include/bits/stl_set.h @@ -1051,15 +1051,6 @@ _GLIBCXX_END_NAMESPACE_CONTAINER _S_get_tree(_GLIBCXX_STD_C::multiset<_Val, _Cmp2, _Alloc>& __set) { return __set._M_t; } }; -#if __cplusplus > 201703L -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool - __enable_view_impl<_GLIBCXX_STD_C::set<_Key, _Compare, _Alloc>> = false; -} // namespace ranges::__detail -#endif // C++20 #endif // C++17 _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/bits/unordered_set.h b/libstdc++-v3/include/bits/unordered_set.h index 824eedbae3e..9c2cd45be9c 100644 --- a/libstdc++-v3/include/bits/unordered_set.h +++ b/libstdc++-v3/include/bits/unordered_set.h @@ -1771,21 +1771,6 @@ _GLIBCXX_END_NAMESPACE_CONTAINER _S_get_table(unordered_multiset<_Val, _Hash2, _Eq2, _Alloc>& __set) { return __set._M_h; } }; - -#if __cplusplus > 201703L -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool - __enable_view_impl<_GLIBCXX_STD_C::unordered_set<_Val, _Hash, _Eq, - _Alloc>> = false; - template - inline constexpr bool - __enable_view_impl<_GLIBCXX_STD_C::unordered_multiset<_Val, _Hash, _Eq, - _Alloc>> = false; -} // namespace ranges::__detail -#endif // C++20 #endif // C++17 _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/include/debug/multiset.h b/libstdc++-v3/include/debug/multiset.h index f5b974ccdc4..fcbba339478 100644 --- a/libstdc++-v3/include/debug/multiset.h +++ b/libstdc++-v3/include/debug/multiset.h @@ -630,19 +630,6 @@ namespace __debug { return __x.swap(__y); } } // namespace __debug - -#if __cplusplus > 201703L -_GLIBCXX_BEGIN_NAMESPACE_VERSION -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool - __enable_view_impl> - = false; -} // namespace ranges::__detail -_GLIBCXX_END_NAMESPACE_VERSION -#endif // C++20 } // namespace std #endif diff --git a/libstdc++-v3/include/debug/set.h b/libstdc++-v3/include/debug/set.h index f3f90476a48..093ff129f3e 100644 --- a/libstdc++-v3/include/debug/set.h +++ b/libstdc++-v3/include/debug/set.h @@ -641,18 +641,6 @@ namespace __debug { return __x.swap(__y); } } // namespace __debug - -#if __cplusplus > 201703L -_GLIBCXX_BEGIN_NAMESPACE_VERSION -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool - __enable_view_impl> = false; -} // namespace ranges::__detail -_GLIBCXX_END_NAMESPACE_VERSION -#endif // C++20 } // namespace std #endif diff --git a/libstdc++-v3/include/debug/unordered_set b/libstdc++-v3/include/debug/unordered_set index 040ae7f2ad4..9941bbe1c24 100644 --- a/libstdc++-v3/include/debug/unordered_set +++ b/libstdc++-v3/include/debug/unordered_set @@ -1183,22 +1183,6 @@ namespace __debug { return !(__x == __y); } } // namespace __debug -#if __cplusplus > 201703L -_GLIBCXX_BEGIN_NAMESPACE_VERSION -namespace ranges::__detail -{ - template extern inline const bool __enable_view_impl; - template - inline constexpr bool - __enable_view_impl> - = false; - template - inline constexpr bool - __enable_view_impl> = false; -} // namespace ranges::__detail -_GLIBCXX_END_NAMESPACE_VERSION -#endif // C++20 } // namespace std #endif // C++11 diff --git a/libstdc++-v3/include/experimental/string_view b/libstdc++-v3/include/experimental/string_view index 439650154ae..629db577c29 100644 --- a/libstdc++-v3/include/experimental/string_view +++ b/libstdc++-v3/include/experimental/string_view @@ -694,12 +694,16 @@ namespace experimental #if __cpp_lib_concepts namespace ranges { - template extern inline const bool enable_borrowed_range; // Opt-in to borrowed_range concept template inline constexpr bool enable_borrowed_range> = true; + + // Opt-in to view concept + template + inline constexpr bool + enable_view> = true; } #endif diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges index 8c925fa278b..0b2057c9661 100644 --- a/libstdc++-v3/include/std/ranges +++ b/libstdc++-v3/include/std/ranges @@ -65,25 +65,8 @@ namespace ranges struct view_base { }; - namespace __detail - { - template - concept __deep_const_range = range<_Tp> && range - && same_as, range_reference_t>; - - template - inline constexpr bool __enable_view_impl - = derived_from<_Tp, view_base> || (!__deep_const_range<_Tp>); - - template - inline constexpr bool __enable_view_impl> - = false; - - } // namespace __detail - template - inline constexpr bool enable_view - = __detail::__enable_view_impl>; + inline constexpr bool enable_view = derived_from<_Tp, view_base>; template concept view diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span index 16b09a1e50c..f658adb04cf 100644 --- a/libstdc++-v3/include/std/span +++ b/libstdc++-v3/include/std/span @@ -447,11 +447,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION namespace ranges { - template extern inline const bool enable_borrowed_range; // Opt-in to borrowed_range concept template inline constexpr bool enable_borrowed_range> = true; + + // Opt-in to view concept + template + inline constexpr bool + enable_view> + = _Extent == 0 || _Extent == dynamic_extent; } _GLIBCXX_END_NAMESPACE_VERSION } // namespace std diff --git a/libstdc++-v3/include/std/string_view b/libstdc++-v3/include/std/string_view index 16687f6c352..ea5d547e006 100644 --- a/libstdc++-v3/include/std/string_view +++ b/libstdc++-v3/include/std/string_view @@ -727,11 +727,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION #if __cpp_lib_concepts namespace ranges { - template extern inline const bool enable_borrowed_range; // Opt-in to borrowed_range concept template inline constexpr bool enable_borrowed_range> = true; + + // Opt-in to view concept + template + inline constexpr bool + enable_view> = true; } #endif _GLIBCXX_END_NAMESPACE_VERSION diff --git a/libstdc++-v3/testsuite/std/ranges/view.cc b/libstdc++-v3/testsuite/std/ranges/view.cc index d76c8013c2c..72e8bcb50d7 100644 --- a/libstdc++-v3/testsuite/std/ranges/view.cc +++ b/libstdc++-v3/testsuite/std/ranges/view.cc @@ -19,13 +19,23 @@ // { dg-do compile { target c++2a } } #include +#include +#include +#include +#include #include #include #include #include #include -static_assert(std::ranges::view>); +static_assert(std::ranges::view>); +static_assert(std::ranges::view>); +static_assert(!std::ranges::view>); +static_assert(std::ranges::view); +static_assert(std::ranges::view); + +static_assert(!std::ranges::view>); static_assert(!std::ranges::view>); static_assert(!std::ranges::view>); static_assert(!std::ranges::view>); -- 2.30.2