[gcc(refs/users/redi/heads/lwg3326)] libstdc++: enable_view has false positives (LWG 3326)
Jonathan Wakely
redi@gcc.gnu.org
Wed Feb 19 13:54:00 GMT 2020
https://gcc.gnu.org/g:eddefb4a3b1f7b7a1ad855572dd32abb2874a0b5
commit eddefb4a3b1f7b7a1ad855572dd32abb2874a0b5
Author: Jonathan Wakely <jwakely@redhat.com>
Date: Wed Feb 19 13:27:56 2020 +0000
libstdc++: enable_view has false positives (LWG 3326)
* include/std/ranges (__deep_const_range, __enable_view_impl): Remove.
(enable_view): Simplify (LWG 3326).
* 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 (enable_view): Define partial
specialization.
* include/std/span (enable_view): Likewise.
* include/std/string_view (enable_view): Likewise.
* testsuite/std/ranges/view.cc: Check satisfaction of updated concept.
Diff:
---
libstdc++-v3/ChangeLog | 16 ++++++++++++++++
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 +++++++++++-
13 files changed, 46 insertions(+), 106 deletions(-)
diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index f01b78d..9f5c0e5 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,21 @@
2020-02-19 Jonathan Wakely <jwakely@redhat.com>
+ * include/std/ranges (__deep_const_range, __enable_view_impl): Remove.
+ (enable_view): Simplify (LWG 3326).
+ * 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 (enable_view): Define partial
+ specialization.
+ * include/std/span (enable_view): Likewise.
+ * include/std/string_view (enable_view): Likewise.
+ * testsuite/std/ranges/view.cc: Check satisfaction of updated concept.
+
* include/bits/range_access.h (range_size_t): Define alias template.
* include/std/ranges (all_view): Rename to views::all_t (LWG 3335).
* testsuite/std/ranges/adaptors/filter.cc: Adjust to new name.
diff --git a/libstdc++-v3/include/bits/regex.h b/libstdc++-v3/include/bits/regex.h
index 3307e1c..dcae83e 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Bi_iter, typename _Alloc>
- inline constexpr bool __enable_view_impl<match_results<_Bi_iter, _Alloc>>
- = 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 b8b8291..ab62df1 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Key, typename _Compare, typename _Alloc>
- 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 5f3e78d..4f8d631 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Key, typename _Compare, typename _Alloc>
- 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 824eedb..9c2cd45 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Val, typename _Hash, typename _Eq, typename _Alloc>
- inline constexpr bool
- __enable_view_impl<_GLIBCXX_STD_C::unordered_set<_Val, _Hash, _Eq,
- _Alloc>> = false;
- template<typename _Val, typename _Hash, typename _Eq, typename _Alloc>
- 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 f5b974c..fcbba33 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Key, typename _Compare, typename _Alloc>
- inline constexpr bool
- __enable_view_impl<std::__debug::multiset<_Key, _Compare, _Alloc>>
- = 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 f3f9047..093ff12 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Key, typename _Compare, typename _Alloc>
- inline constexpr bool
- __enable_view_impl<std::__debug::set<_Key, _Compare, _Alloc>> = 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 040ae7f..9941bbe 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<typename _Tp> extern inline const bool __enable_view_impl;
- template<typename _Val, typename _Hash, typename _Eq, typename _Alloc>
- inline constexpr bool
- __enable_view_impl<std::__debug::unordered_set<_Val, _Hash, _Eq, _Alloc>>
- = false;
- template<typename _Val, typename _Hash, typename _Eq, typename _Alloc>
- inline constexpr bool
- __enable_view_impl<std::__debug::unordered_multiset<_Val, _Hash, _Eq,
- _Alloc>> = 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 4396501..0d37361 100644
--- a/libstdc++-v3/include/experimental/string_view
+++ b/libstdc++-v3/include/experimental/string_view
@@ -700,6 +700,12 @@ namespace experimental
inline constexpr bool
enable_borrowed_range<experimental::basic_string_view<_CharT, _Traits>>
= true;
+
+ template<typename> extern inline const bool enable_view;
+ // Opt-in to view concept
+ template<typename _CharT, typename _Traits>
+ inline constexpr bool
+ enable_view<experimental::basic_string_view<_CharT, _Traits>> = true;
}
#endif
diff --git a/libstdc++-v3/include/std/ranges b/libstdc++-v3/include/std/ranges
index b080675..ff98da8 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<typename _Tp>
- concept __deep_const_range = range<_Tp> && range<const _Tp>
- && same_as<range_reference_t<_Tp>, range_reference_t<const _Tp>>;
-
- template<typename _Tp>
- inline constexpr bool __enable_view_impl
- = derived_from<_Tp, view_base> || (!__deep_const_range<_Tp>);
-
- template<typename _Tp>
- inline constexpr bool __enable_view_impl<std::initializer_list<_Tp>>
- = false;
-
- } // namespace __detail
-
template<typename _Tp>
- inline constexpr bool enable_view
- = __detail::__enable_view_impl<remove_cv_t<_Tp>>;
+ inline constexpr bool enable_view = derived_from<_Tp, view_base>;
template<typename _Tp>
concept view
diff --git a/libstdc++-v3/include/std/span b/libstdc++-v3/include/std/span
index 63dc251..79b4b6f 100644
--- a/libstdc++-v3/include/std/span
+++ b/libstdc++-v3/include/std/span
@@ -465,11 +465,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
namespace ranges
{
- template<typename> extern inline const bool enable_borrowed_range;
// Opt-in to borrowed_range concept
template<typename _ElementType, size_t _Extent>
inline constexpr bool
enable_borrowed_range<span<_ElementType, _Extent>> = true;
+
+ // Opt-in to view concept
+ template<typename _ElementType, size_t _Extent>
+ inline constexpr bool
+ enable_view<span<_ElementType, _Extent>>
+ = _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 16687f6..2f9bb33 100644
--- a/libstdc++-v3/include/std/string_view
+++ b/libstdc++-v3/include/std/string_view
@@ -732,6 +732,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
template<typename _CharT, typename _Traits>
inline constexpr bool
enable_borrowed_range<basic_string_view<_CharT, _Traits>> = true;
+
+ template<typename> extern inline const bool enable_view;
+ // Opt-in to view concept
+ template<typename _CharT, typename _Traits>
+ inline constexpr bool
+ enable_view<basic_string_view<_CharT, _Traits>> = 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 d76c801..72e8bcb 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 <ranges>
+#include <span>
+#include <string_view>
+#include <experimental/string_view>
+#include <vector>
#include <vector>
#include <set>
#include <unordered_set>
#include <regex>
#include <testsuite_iterators.h>
-static_assert(std::ranges::view<std::vector<int>>);
+static_assert(std::ranges::view<std::span<int>>);
+static_assert(std::ranges::view<std::span<int, 0>>);
+static_assert(!std::ranges::view<std::span<int, 1>>);
+static_assert(std::ranges::view<std::string_view>);
+static_assert(std::ranges::view<std::experimental::string_view>);
+
+static_assert(!std::ranges::view<std::vector<int>>);
static_assert(!std::ranges::view<const std::vector<int>>);
static_assert(!std::ranges::view<std::initializer_list<int>>);
static_assert(!std::ranges::view<const std::initializer_list<int>>);
More information about the Libstdc++-cvs
mailing list