]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
libstdc++: [_GLIBCXX_DEBUG] Avoid allocator operator== when always equal
authorFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 9 Aug 2021 09:55:43 +0000 (11:55 +0200)
committerFrançois Dumont <fdumont@gcc.gnu.org>
Mon, 9 Aug 2021 18:44:58 +0000 (20:44 +0200)
Use std::allocator_traits::is_always_equal to find out if we need to compare
allocator instances on safe container allocator aware move constructor.

libstdc++-v3/ChangeLog:

* include/debug/safe_container.h
(_Safe_container(_Safe_container&&, const _Alloc&, std::true_type)): New.
(_Safe_container(_Safe_container&&, const _Alloc&, std::false_type)): New.
(_Safe_container(_Safe_container&&, const _Alloc&)): Use latters.

libstdc++-v3/include/debug/safe_container.h

index d9636c29e9b5ab638c082d694860f4ef68e47135..97c47167fe8fb0e2b6feaeb415a1f07db79b545a 100644 (file)
@@ -57,7 +57,12 @@ namespace __gnu_debug
       _Safe_container(const _Safe_container&) = default;
       _Safe_container(_Safe_container&&) = default;
 
-      _Safe_container(_Safe_container&& __x, const _Alloc& __a)
+    private:
+      _Safe_container(_Safe_container&& __x, const _Alloc&, std::true_type)
+      : _Safe_container(std::move(__x))
+      { }
+
+      _Safe_container(_Safe_container&& __x, const _Alloc& __a, std::false_type)
       : _Safe_container()
       {
        if (__x._M_cont().get_allocator() == __a)
@@ -65,6 +70,12 @@ namespace __gnu_debug
        else
          __x._M_invalidate_all();
       }
+
+    protected:
+      _Safe_container(_Safe_container&& __x, const _Alloc& __a)
+      : _Safe_container(std::move(__x), __a,
+                     typename std::allocator_traits<_Alloc>::is_always_equal{})
+      { }
 #endif
 
     public: