]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: Restore debug checks in uniform container erasure functions
authorJonathan Wakely <jwakely@redhat.com>
Thu, 7 Oct 2021 19:33:45 +0000 (20:33 +0100)
committerJonathan Wakely <jwakely@redhat.com>
Fri, 8 Oct 2021 11:20:25 +0000 (12:20 +0100)
This partially reverts commit 561078480ffb5adb68577276c6b23e4ee7b39272.

If we avoid all debug mode checks when erasing elements then we fail to
invalidate safe iterators to the removed elements. This reverts the
recent changes in r12-4083 and r12-4233, restoring the debug checking.

libstdc++-v3/ChangeLog:

* include/experimental/deque (erase, erase_if): Revert changes
to avoid debug mode overhead.
* include/experimental/map (erase, erase_if): Likewise.
* include/experimental/set (erase, erase_if): Likewise.
* include/experimental/unordered_map (erase, erase_if):
Likewise.
* include/experimental/unordered_set (erase, erase_if):
Likewise.
* include/experimental/vector (erase, erase_if): Likewise.
* include/std/deque (erase, erase_if): Likewise.
* include/std/map (erase, erase_if): Likewise.
* include/std/set (erase, erase_if): Likewise.
* include/std/unordered_map (erase, erase_if): Likewise.
* include/std/unordered_set (erase, erase_if): Likewise.
* include/std/vector (erase, erase_if): Likewise.

12 files changed:
libstdc++-v3/include/experimental/deque
libstdc++-v3/include/experimental/map
libstdc++-v3/include/experimental/set
libstdc++-v3/include/experimental/unordered_map
libstdc++-v3/include/experimental/unordered_set
libstdc++-v3/include/experimental/vector
libstdc++-v3/include/std/deque
libstdc++-v3/include/std/map
libstdc++-v3/include/std/set
libstdc++-v3/include/std/unordered_map
libstdc++-v3/include/std/unordered_set
libstdc++-v3/include/std/vector

index 710833ebcaded99b557ad800e7d6121f003229a2..a76fb659bbf67f2064ed508f0790d127fdbebd24 100644 (file)
@@ -50,16 +50,16 @@ inline namespace fundamentals_v2
     inline void
     erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred)
     {
-      _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont;
-      __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
+      __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred),
+                  __cont.end());
     }
 
   template<typename _Tp, typename _Alloc, typename _Up>
     inline void
     erase(deque<_Tp, _Alloc>& __cont, const _Up& __value)
     {
-      _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont;
-      __c.erase(std::remove(__c.begin(), __c.end(), __value), __c.end());
+      __cont.erase(std::remove(__cont.begin(), __cont.end(), __value),
+                  __cont.end());
     }
 
   namespace pmr {
index ef69fadf9441ac0332ab227c1135572cf5262035..0c0f42222f5697f392bd94ae6aec623fb667b453 100644 (file)
@@ -50,19 +50,13 @@ inline namespace fundamentals_v2
           typename _Predicate>
     inline void
     erase_if(map<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Alloc>& __c = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc,
           typename _Predicate>
     inline void
     erase_if(multimap<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Alloc>& __c = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   namespace pmr {
     template<typename _Key, typename _Tp, typename _Compare = less<_Key>>
index 7a5986aec0e9b03b5f46b6be2ff21590fe816ca1..c3f5433e995c3c62cb7966a0f4181e7142818831 100644 (file)
@@ -50,19 +50,13 @@ inline namespace fundamentals_v2
           typename _Predicate>
     inline void
     erase_if(set<_Key, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::set<_Key, _Compare, _Alloc>& __c = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Compare, typename _Alloc,
           typename _Predicate>
     inline void
     erase_if(multiset<_Key, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::multiset<_Key, _Compare, _Alloc>& __c = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   namespace pmr {
     template<typename _Key, typename _Compare = less<_Key>>
index eba989713fa096601ed6ec1bda067187284fd865..0b915ab13e5bd148f6b93fcd6beba8eb7abf59ec 100644 (file)
@@ -51,22 +51,14 @@ inline namespace fundamentals_v2
     inline void
     erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __c
-       = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Tp, typename _Hash, typename _CPred,
           typename _Alloc, typename _Predicate>
     inline void
     erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __c
-       = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   namespace pmr {
     template<typename _Key, typename _Tp, typename _Hash = hash<_Key>,
index bc5cc11419e091e0da772a54fbd2e9282c8868c5..87db4464401eb1407f283d566a2a6797069a2f23 100644 (file)
@@ -51,21 +51,14 @@ inline namespace fundamentals_v2
     inline void
     erase_if(unordered_set<_Key, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_set<_Key, _Hash, _CPred, _Alloc>& __c = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Hash, typename _CPred, typename _Alloc,
           typename _Predicate>
     inline void
     erase_if(unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __c
-       = __cont;
-      std::__detail::__erase_nodes_if(__c, __pred);
-    }
+    { std::__detail::__erase_nodes_if(__cont, __pred); }
 
   namespace pmr {
     template<typename _Key, typename _Hash = hash<_Key>,
index c45a500ef5e676990f5101a516d0e5ad8676a230..a14aedf33640889f433de21eb9c4dd4e55bb8d12 100644 (file)
@@ -52,16 +52,16 @@ inline namespace fundamentals_v2
     inline void
     erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred)
     {
-      _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont;
-      __c.erase(std::remove_if(__c.begin(), __c.end(), __pred), __c.end());
+      __cont.erase(std::remove_if(__cont.begin(), __cont.end(), __pred),
+                  __cont.end());
     }
 
   template<typename _Tp, typename _Alloc, typename _Up>
     inline void
     erase(vector<_Tp, _Alloc>& __cont, const _Up& __value)
     {
-      _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont;
-      __c.erase(std::remove(__c.begin(), __c.end(), __value), __c.end());
+      __cont.erase(std::remove(__cont.begin(), __cont.end(), __value),
+                  __cont.end());
     }
 
   namespace pmr {
index 71993e757a516ad2c12de8602d5ac876093e5830..473479c44ac8e7157fa557c31aa24e21e4af6489 100644 (file)
@@ -95,28 +95,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline typename deque<_Tp, _Alloc>::size_type
     erase_if(deque<_Tp, _Alloc>& __cont, _Predicate __pred)
     {
-      _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont;
       using namespace __gnu_cxx;
-      const auto __osz = __c.size();
-      const auto __end = __c.end();
-      auto __removed = std::__remove_if(__c.begin(), __end,
+      const auto __osz = __cont.size();
+      const auto __end = __cont.end();
+      auto __removed = std::__remove_if(__cont.begin(), __end,
                                        __ops::__pred_iter(std::ref(__pred)));
-      __c.erase(__removed, __end);
-      return __osz - __c.size();
+      __cont.erase(__removed, __end);
+      return __osz - __cont.size();
     }
 
   template<typename _Tp, typename _Alloc, typename _Up>
     inline typename deque<_Tp, _Alloc>::size_type
     erase(deque<_Tp, _Alloc>& __cont, const _Up& __value)
     {
-      _GLIBCXX_STD_C::deque<_Tp, _Alloc>& __c = __cont;
       using namespace __gnu_cxx;
-      const auto __osz = __c.size();
-      const auto __end = __c.end();
-      auto __removed = std::__remove_if(__c.begin(), __end,
+      const auto __osz = __cont.size();
+      const auto __end = __cont.end();
+      auto __removed = std::__remove_if(__cont.begin(), __end,
                                        __ops::__iter_equals_val(__value));
-      __c.erase(__removed, __end);
-      return __osz - __c.size();
+      __cont.erase(__removed, __end);
+      return __osz - __cont.size();
     }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
index 29265580995f6636e23a8be5cec0962c5a178bc9..44bd44b5922a44cd4e1c971ee8633578ad878c6a 100644 (file)
@@ -95,19 +95,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
           typename _Predicate>
     inline typename map<_Key, _Tp, _Compare, _Alloc>::size_type
     erase_if(map<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::map<_Key, _Tp, _Compare, _Alloc>& __c = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Tp, typename _Compare, typename _Alloc,
           typename _Predicate>
     inline typename multimap<_Key, _Tp, _Compare, _Alloc>::size_type
     erase_if(multimap<_Key, _Tp, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::multimap<_Key, _Tp, _Compare, _Alloc>& __c = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 #endif // C++20
index 24e6e6336248383e50ec668a4075393d3cff6dd4..f1e1864937a0b4b8cf5d5a60878d9c4090ed4064 100644 (file)
@@ -91,19 +91,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
           typename _Predicate>
     inline typename set<_Key, _Compare, _Alloc>::size_type
     erase_if(set<_Key, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::set<_Key, _Compare, _Alloc>& __c = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Compare, typename _Alloc,
           typename _Predicate>
     inline typename multiset<_Key, _Compare, _Alloc>::size_type
     erase_if(multiset<_Key, _Compare, _Alloc>& __cont, _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::multiset<_Key, _Compare, _Alloc>& __c = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 #endif // C++20
index 774c21fc28b207d9e7465b136891b8b3b763b69f..e6715069362d700ff9138e24de0fddae911a117a 100644 (file)
@@ -83,11 +83,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline typename unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>::size_type
     erase_if(unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_map<_Key, _Tp, _Hash, _CPred, _Alloc>& __c
-       = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Tp, typename _Hash, typename _CPred,
           typename _Alloc, typename _Predicate>
@@ -95,11 +91,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
                    size_type
     erase_if(unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_multimap<_Key, _Tp, _Hash, _CPred, _Alloc>& __c
-       = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 #endif // C++20
index 3859eeaebd09732a579c4d218b38799cb9498695..1ad93d0031b2c6a84077846549356559e3da757a 100644 (file)
@@ -83,21 +83,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline typename unordered_set<_Key, _Hash, _CPred, _Alloc>::size_type
     erase_if(unordered_set<_Key, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_set<_Key, _Hash, _CPred, _Alloc>& __c = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 
   template<typename _Key, typename _Hash, typename _CPred, typename _Alloc,
           typename _Predicate>
     inline typename unordered_multiset<_Key, _Hash, _CPred, _Alloc>::size_type
     erase_if(unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __cont,
             _Predicate __pred)
-    {
-      _GLIBCXX_STD_C::unordered_multiset<_Key, _Hash, _CPred, _Alloc>& __c
-       = __cont;
-      return __detail::__erase_nodes_if(__c, __pred);
-    }
+    { return __detail::__erase_nodes_if(__cont, __pred); }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std
 #endif // C++20
index 835fa8aeb691f28ebbb41545ba07ee21727ba853..096511c05b20101aa6ddcacfbcd3e66f419190ab 100644 (file)
@@ -105,28 +105,26 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline typename vector<_Tp, _Alloc>::size_type
     erase_if(vector<_Tp, _Alloc>& __cont, _Predicate __pred)
     {
-      _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont;
       using namespace __gnu_cxx;
-      const auto __osz = __c.size();
-      const auto __end = __c.end();
-      auto __removed(std::__remove_if(__c.begin(), __end,
-                                     __ops::__pred_iter(std::ref(__pred))));
-      __c.erase(__removed, __end);
-      return __osz - __c.size();
+      const auto __osz = __cont.size();
+      const auto __end = __cont.end();
+      auto __removed = std::__remove_if(__cont.begin(), __end,
+                                       __ops::__pred_iter(std::ref(__pred)));
+      __cont.erase(__removed, __end);
+      return __osz - __cont.size();
     }
 
   template<typename _Tp, typename _Alloc, typename _Up>
     inline typename vector<_Tp, _Alloc>::size_type
     erase(vector<_Tp, _Alloc>& __cont, const _Up& __value)
     {
-      _GLIBCXX_STD_C::vector<_Tp, _Alloc>& __c = __cont;
       using namespace __gnu_cxx;
-      const auto __osz = __c.size();
-      const auto __end = __c.end();
-      auto __removed = std::__remove_if(__c.begin(), __end,
+      const auto __osz = __cont.size();
+      const auto __end = __cont.end();
+      auto __removed = std::__remove_if(__cont.begin(), __end,
                                        __ops::__iter_equals_val(__value));
-      __c.erase(__removed, __end);
-      return __osz - __c.size();
+      __cont.erase(__removed, __end);
+      return __osz - __cont.size();
     }
 _GLIBCXX_END_NAMESPACE_VERSION
 } // namespace std