public inbox for libstdc++@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH][_GLIBCXX_DEBUG] Fix std::__niter_base behavior
@ 2024-02-14 18:39 François Dumont
  2024-02-14 19:44 ` Jonathan Wakely
  0 siblings, 1 reply; 14+ messages in thread
From: François Dumont @ 2024-02-14 18:39 UTC (permalink / raw)
  To: libstdc++; +Cc: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 594 bytes --]

libstdc++: [_GLIBCXX_DEBUG] Fix std::__niter_base behavior

std::__niter_base is used in _GLIBCXX_DEBUG mode to remove _Safe_iterator<>
wrapper on random access iterators. But doing so it should also preserve 
original
behavior to remove __normal_iterator wrapper.

libstdc++-v3/ChangeLog:

     * include/bits/stl_algobase.h (std::__niter_base): Redefine the 
overload
     definitions for __gnu_debug::_Safe_iterator.
     * include/debug/safe_iterator.tcc (std::__niter_base): Adapt 
declarations.

Ok to commit once all tests completed (still need to check pre-c++11) ?

François

[-- Attachment #2: niter_base_patch.txt --]
[-- Type: text/plain, Size: 2663 bytes --]

diff --git a/libstdc++-v3/include/bits/stl_algobase.h b/libstdc++-v3/include/bits/stl_algobase.h
index e7207f67266..056fa0c4173 100644
--- a/libstdc++-v3/include/bits/stl_algobase.h
+++ b/libstdc++-v3/include/bits/stl_algobase.h
@@ -317,12 +317,27 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _GLIBCXX_NOEXCEPT_IF(std::is_nothrow_copy_constructible<_Iterator>::value)
     { return __it; }
 
+#if __cplusplus < 201103L
   template<typename _Ite, typename _Seq>
-    _GLIBCXX20_CONSTEXPR
     _Ite
     __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
 		 std::random_access_iterator_tag>&);
 
+ template<typename _Ite, typename _Cont, typename _Seq>
+    _Ite
+    __niter_base(const ::__gnu_debug::_Safe_iterator<
+		 ::__gnu_cxx::__normal_iterator<_Ite, _Cont>, _Seq,
+		 std::random_access_iterator_tag>&);
+#else
+  template<typename _Ite, typename _Seq>
+    _GLIBCXX20_CONSTEXPR
+    decltype(std::__niter_base(std::declval<_Ite>()))
+    __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
+		 std::random_access_iterator_tag>&)
+    noexcept( noexcept(std::is_nothrow_copy_constructible<
+	decltype(std::__niter_base(std::declval<_Ite>()))>::value) );
+#endif
+
   // Reverse the __niter_base transformation to get a
   // __normal_iterator back again (this assumes that __normal_iterator
   // is only used to wrap random access iterators, like pointers).
diff --git a/libstdc++-v3/include/debug/safe_iterator.tcc b/libstdc++-v3/include/debug/safe_iterator.tcc
index 6eb70cbda04..d6cfe24cc83 100644
--- a/libstdc++-v3/include/debug/safe_iterator.tcc
+++ b/libstdc++-v3/include/debug/safe_iterator.tcc
@@ -235,13 +235,29 @@ namespace std _GLIBCXX_VISIBILITY(default)
 {
 _GLIBCXX_BEGIN_NAMESPACE_VERSION
 
+#if __cplusplus < 201103L
   template<typename _Ite, typename _Seq>
-    _GLIBCXX20_CONSTEXPR
     _Ite
     __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
 		 std::random_access_iterator_tag>& __it)
     { return __it.base(); }
 
+  template<typename _Ite, typename _Cont, typename _DbgSeq>
+    _Ite
+    __niter_base(const ::__gnu_debug::_Safe_iterator<
+		 ::__gnu_cxx::__normal_iterator<_Ite, _Cont>, _DbgSeq,
+		 std::random_access_iterator_tag>& __it)
+    { return __it.base().base(); }
+#else
+  template<typename _Ite, typename _Seq>
+    _GLIBCXX20_CONSTEXPR
+    auto
+    __niter_base(const ::__gnu_debug::_Safe_iterator<_Ite, _Seq,
+		 std::random_access_iterator_tag>& __it)
+    -> decltype(std::__niter_base(declval<_Ite>()))
+    { return std::__niter_base(__it.base()); }
+#endif
+
   template<bool _IsMove,
 	   typename _Ite, typename _Seq, typename _Cat, typename _OI>
     _GLIBCXX20_CONSTEXPR

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2024-02-20 19:27 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14 18:39 [PATCH][_GLIBCXX_DEBUG] Fix std::__niter_base behavior François Dumont
2024-02-14 19:44 ` Jonathan Wakely
2024-02-14 21:48   ` François Dumont
2024-02-15 13:17     ` Jonathan Wakely
2024-02-15 18:38       ` François Dumont
2024-02-15 18:40         ` Jonathan Wakely
2024-02-17 14:14           ` François Dumont
2024-02-19  7:07             ` Stephan Bergmann
2024-02-19  8:12               ` Jonathan Wakely
2024-02-19  8:21                 ` Jonathan Wakely
2024-02-19 18:39                   ` François Dumont
2024-02-20 18:42                   ` François Dumont
2024-02-20 19:27                     ` Jonathan Wakely
2024-02-19 17:59               ` François Dumont

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).