[gcc(refs/users/guojiufu/heads/guojiufu-branch)] libstdc++: Add comparison operators to types from Utilities clause

Jiu Fu Guo guojiufu@gcc.gnu.org
Mon Apr 27 09:30:56 GMT 2020


https://gcc.gnu.org/g:596676d66cab21e5ed85669e737af5b62f067d57

commit 596676d66cab21e5ed85669e737af5b62f067d57
Author: Jonathan Wakely <jwakely@redhat.com>
Date:   Wed Apr 15 19:47:48 2020 +0100

    libstdc++: Add comparison operators to types from Utilities clause
    
    Some more C++20 changes from P1614R2, "The Mothership has Landed".
    
    This removes all redundant equality and inequality operators in the
    Utilities clause, as they can be synthesized from the remaining equality
    operators.
    
    It also removes the single redundant operator in the Localization
    clause, because it didn't seem worth doing in a separate commit.
    
            * include/bits/allocator.h (operator!=): Do not define for C++20.
            * include/bits/locale_classes.h (operator!=): Likewise.
            * include/bits/std_function.h (operator==(nullptr_t, const function&))
            (operator!=(const function&, nullptr_t))
            (operator!=(nullptr_t, const function&)): Likewise.
            * include/ext/bitmap_allocator.h (operator!=): Likewise.
            * include/ext/debug_allocator.h (operator!=): Likewise.
            * include/ext/extptr_allocator.h (operator!=): Likewise.
            * include/ext/malloc_allocator.h (operator!=): Likewise.
            * include/ext/mt_allocator.h (operator!=): Likewise.
            * include/ext/new_allocator.h (operator!=): Likewise.
            * include/ext/pool_allocator.h (operator!=): Likewise.
            * include/ext/throw_allocator.h (operator!=): Likewise.
            * include/std/bitset (bitset::operator!=): Likewise.
            * include/std/memory_resource (operator!=): Likewise.
            * include/std/scoped_allocator (operator!=): Likewise.

Diff:
---
 libstdc++-v3/ChangeLog                      | 17 +++++++++++++++++
 libstdc++-v3/include/bits/allocator.h       |  4 ++++
 libstdc++-v3/include/bits/locale_classes.h  |  2 ++
 libstdc++-v3/include/bits/std_function.h    |  3 ++-
 libstdc++-v3/include/ext/bitmap_allocator.h |  4 +++-
 libstdc++-v3/include/ext/debug_allocator.h  |  2 ++
 libstdc++-v3/include/ext/extptr_allocator.h |  2 ++
 libstdc++-v3/include/ext/malloc_allocator.h |  2 ++
 libstdc++-v3/include/ext/mt_allocator.h     |  2 ++
 libstdc++-v3/include/ext/new_allocator.h    |  2 ++
 libstdc++-v3/include/ext/pool_allocator.h   |  2 ++
 libstdc++-v3/include/ext/throw_allocator.h  |  2 ++
 libstdc++-v3/include/std/bitset             |  2 ++
 libstdc++-v3/include/std/memory_resource    |  6 ++++--
 libstdc++-v3/include/std/scoped_allocator   |  2 ++
 15 files changed, 50 insertions(+), 4 deletions(-)

diff --git a/libstdc++-v3/ChangeLog b/libstdc++-v3/ChangeLog
index 696a423e5c7..ac446acaaac 100644
--- a/libstdc++-v3/ChangeLog
+++ b/libstdc++-v3/ChangeLog
@@ -1,5 +1,22 @@
 2020-04-15  Jonathan Wakely  <jwakely@redhat.com>
 
+	* include/bits/allocator.h (operator!=): Do not define for C++20.
+	* include/bits/locale_classes.h (operator!=): Likewise.
+	* include/bits/std_function.h (operator==(nullptr_t, const function&))
+	(operator!=(const function&, nullptr_t))
+	(operator!=(nullptr_t, const function&)): Likewise.
+	* include/ext/bitmap_allocator.h (operator!=): Likewise.
+	* include/ext/debug_allocator.h (operator!=): Likewise.
+	* include/ext/extptr_allocator.h (operator!=): Likewise.
+	* include/ext/malloc_allocator.h (operator!=): Likewise.
+	* include/ext/mt_allocator.h (operator!=): Likewise.
+	* include/ext/new_allocator.h (operator!=): Likewise.
+	* include/ext/pool_allocator.h (operator!=): Likewise.
+	* include/ext/throw_allocator.h (operator!=): Likewise.
+	* include/std/bitset (bitset::operator!=): Likewise.
+	* include/std/memory_resource (operator!=): Likewise.
+	* include/std/scoped_allocator (operator!=): Likewise.
+
 	* include/std/typeindex (operator<=>): Define for C++20.
 	* testsuite/20_util/typeindex/comparison_operators_c++20.cc: New test.
 
diff --git a/libstdc++-v3/include/bits/allocator.h b/libstdc++-v3/include/bits/allocator.h
index 3e0d608aa6b..ee564791dfa 100644
--- a/libstdc++-v3/include/bits/allocator.h
+++ b/libstdc++-v3/include/bits/allocator.h
@@ -196,9 +196,11 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       operator==(const allocator&, const allocator&) _GLIBCXX_NOTHROW
       { return true; }
 
+#if __cpp_impl_three_way_comparison < 201907L
       friend _GLIBCXX20_CONSTEXPR bool
       operator!=(const allocator&, const allocator&) _GLIBCXX_NOTHROW
       { return false; }
+#endif
 
       // Inherit everything else.
     };
@@ -209,11 +211,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     _GLIBCXX_NOTHROW
     { return true; }
 
+#if __cpp_impl_three_way_comparison < 201907L
   template<typename _T1, typename _T2>
     inline _GLIBCXX20_CONSTEXPR bool
     operator!=(const allocator<_T1>&, const allocator<_T2>&)
     _GLIBCXX_NOTHROW
     { return false; }
+#endif
 
   // Invalid allocator<cv T> partial specializations.
   // allocator_traits::rebind_alloc can be used to form a valid allocator type.
diff --git a/libstdc++-v3/include/bits/locale_classes.h b/libstdc++-v3/include/bits/locale_classes.h
index 11bdddd3dcd..ab90682cde2 100644
--- a/libstdc++-v3/include/bits/locale_classes.h
+++ b/libstdc++-v3/include/bits/locale_classes.h
@@ -254,6 +254,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     bool
     operator==(const locale& __other) const throw();
 
+#if __cpp_impl_three_way_comparison < 201907L
     /**
      *  @brief  Locale inequality.
      *
@@ -263,6 +264,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     bool
     operator!=(const locale& __other) const throw()
     { return !(this->operator==(__other)); }
+#endif
 
     /**
      *  @brief  Compare two strings according to collate.
diff --git a/libstdc++-v3/include/bits/std_function.h b/libstdc++-v3/include/bits/std_function.h
index 57375b5de0c..e2bf9b91850 100644
--- a/libstdc++-v3/include/bits/std_function.h
+++ b/libstdc++-v3/include/bits/std_function.h
@@ -680,6 +680,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     operator==(const function<_Res(_Args...)>& __f, nullptr_t) noexcept
     { return !static_cast<bool>(__f); }
 
+#if __cpp_impl_three_way_comparison < 201907L
   /// @overload
   template<typename _Res, typename... _Args>
     inline bool
@@ -703,7 +704,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     inline bool
     operator!=(nullptr_t, const function<_Res(_Args...)>& __f) noexcept
     { return static_cast<bool>(__f); }
-
+#endif
 
   // [20.7.15.2.7] specialized algorithms
 
diff --git a/libstdc++-v3/include/ext/bitmap_allocator.h b/libstdc++-v3/include/ext/bitmap_allocator.h
index 97b89e14c8c..edddf32fb97 100644
--- a/libstdc++-v3/include/ext/bitmap_allocator.h
+++ b/libstdc++-v3/include/ext/bitmap_allocator.h
@@ -1098,11 +1098,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	       const bitmap_allocator<_Tp2>&) throw()
     { return true; }
   
+#if __cpp_impl_three_way_comparison < 201907L
   template<typename _Tp1, typename _Tp2>
     bool 
     operator!=(const bitmap_allocator<_Tp1>&, 
 	       const bitmap_allocator<_Tp2>&) throw() 
-  { return false; }
+    { return false; }
+#endif
 
   // Static member definitions.
   template<typename _Tp>
diff --git a/libstdc++-v3/include/ext/debug_allocator.h b/libstdc++-v3/include/ext/debug_allocator.h
index 879bb9cfc05..9946faa10a6 100644
--- a/libstdc++-v3/include/ext/debug_allocator.h
+++ b/libstdc++-v3/include/ext/debug_allocator.h
@@ -179,11 +179,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 		   const debug_allocator<_Alloc2>& __rhs) _GLIBCXX_NOTHROW
 	{ return __lhs._M_allocator == debug_allocator(__rhs)._M_allocator; }
 
+#if __cpp_impl_three_way_comparison < 201907L
       template<typename _Alloc2>
 	friend bool
 	operator!=(const debug_allocator& __lhs,
 		   const debug_allocator<_Alloc2>& __rhs) _GLIBCXX_NOTHROW
 	{ return !(__lhs == __rhs); }
+#endif
     };
 
 _GLIBCXX_END_NAMESPACE_VERSION
diff --git a/libstdc++-v3/include/ext/extptr_allocator.h b/libstdc++-v3/include/ext/extptr_allocator.h
index 88090548b7c..850ca286ef6 100644
--- a/libstdc++-v3/include/ext/extptr_allocator.h
+++ b/libstdc++-v3/include/ext/extptr_allocator.h
@@ -138,6 +138,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       operator==(const _ExtPtr_allocator& __rarg) const
       { return _M_real_alloc == __rarg._M_real_alloc; }
 
+#if __cpp_impl_three_way_comparison < 201907L
       template<typename _Up>
         inline bool
         operator!=(const _ExtPtr_allocator<_Up>& __rarg) const
@@ -146,6 +147,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
       inline bool
       operator!=(const _ExtPtr_allocator& __rarg) const
       { return _M_real_alloc != __rarg._M_real_alloc; }
+#endif
 
       template<typename _Up>
         inline friend void
diff --git a/libstdc++-v3/include/ext/malloc_allocator.h b/libstdc++-v3/include/ext/malloc_allocator.h
index e0d59e5620f..1f41660fac7 100644
--- a/libstdc++-v3/include/ext/malloc_allocator.h
+++ b/libstdc++-v3/include/ext/malloc_allocator.h
@@ -174,11 +174,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_GLIBCXX_NOTHROW
 	{ return true; }
 
+#if __cpp_impl_three_way_comparison < 201907L
       template<typename _Up>
 	friend _GLIBCXX20_CONSTEXPR bool
 	operator!=(const malloc_allocator&, const malloc_allocator<_Up>&)
 	_GLIBCXX_NOTHROW
 	{ return false; }
+#endif
 
     private:
       _GLIBCXX_CONSTEXPR size_type
diff --git a/libstdc++-v3/include/ext/mt_allocator.h b/libstdc++-v3/include/ext/mt_allocator.h
index 49e0a8ff836..0857390e665 100644
--- a/libstdc++-v3/include/ext/mt_allocator.h
+++ b/libstdc++-v3/include/ext/mt_allocator.h
@@ -771,10 +771,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     operator==(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&)
     { return true; }
   
+#if __cpp_impl_three_way_comparison < 201907L
   template<typename _Tp, typename _Poolp>
     inline bool
     operator!=(const __mt_alloc<_Tp, _Poolp>&, const __mt_alloc<_Tp, _Poolp>&)
     { return false; }
+#endif
 
 #undef __thread_default
 
diff --git a/libstdc++-v3/include/ext/new_allocator.h b/libstdc++-v3/include/ext/new_allocator.h
index 3639f3cbffe..959d6880276 100644
--- a/libstdc++-v3/include/ext/new_allocator.h
+++ b/libstdc++-v3/include/ext/new_allocator.h
@@ -173,11 +173,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	_GLIBCXX_NOTHROW
 	{ return true; }
 
+#if __cpp_impl_three_way_comparison < 201907L
       template<typename _Up>
 	friend _GLIBCXX20_CONSTEXPR bool
 	operator!=(const new_allocator&, const new_allocator<_Up>&)
 	_GLIBCXX_NOTHROW
 	{ return false; }
+#endif
 
     private:
       _GLIBCXX_CONSTEXPR size_type
diff --git a/libstdc++-v3/include/ext/pool_allocator.h b/libstdc++-v3/include/ext/pool_allocator.h
index cb5bbc2cbb1..c247c403bec 100644
--- a/libstdc++-v3/include/ext/pool_allocator.h
+++ b/libstdc++-v3/include/ext/pool_allocator.h
@@ -198,10 +198,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
     operator==(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&)
     { return true; }
 
+#if __cpp_impl_three_way_comparison < 201907L
   template<typename _Tp>
     inline bool
     operator!=(const __pool_alloc<_Tp>&, const __pool_alloc<_Tp>&)
     { return false; }
+#endif
 
   template<typename _Tp>
     _Atomic_word
diff --git a/libstdc++-v3/include/ext/throw_allocator.h b/libstdc++-v3/include/ext/throw_allocator.h
index 6b0b0a4a150..f99b26b0cf1 100644
--- a/libstdc++-v3/include/ext/throw_allocator.h
+++ b/libstdc++-v3/include/ext/throw_allocator.h
@@ -895,11 +895,13 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
 	       const throw_allocator_base<_Tp, _Cond>&)
     { return true; }
 
+#if __cpp_impl_three_way_comparison < 201907L
   template<typename _Tp, typename _Cond>
     inline bool
     operator!=(const throw_allocator_base<_Tp, _Cond>&,
 	       const throw_allocator_base<_Tp, _Cond>&)
     { return false; }
+#endif
 
   /// Allocator throwing via limit condition.
   template<typename _Tp>
diff --git a/libstdc++-v3/include/std/bitset b/libstdc++-v3/include/std/bitset
index 93296b9e623..5364e59f466 100644
--- a/libstdc++-v3/include/std/bitset
+++ b/libstdc++-v3/include/std/bitset
@@ -1306,9 +1306,11 @@ _GLIBCXX_BEGIN_NAMESPACE_CONTAINER
       operator==(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
       { return this->_M_is_equal(__rhs); }
 
+#if __cpp_impl_three_way_comparison < 201907L
       bool
       operator!=(const bitset<_Nb>& __rhs) const _GLIBCXX_NOEXCEPT
       { return !this->_M_is_equal(__rhs); }
+#endif
       //@}
 
       /**
diff --git a/libstdc++-v3/include/std/memory_resource b/libstdc++-v3/include/std/memory_resource
index 74683c5267f..f87ef9688f3 100644
--- a/libstdc++-v3/include/std/memory_resource
+++ b/libstdc++-v3/include/std/memory_resource
@@ -122,10 +122,11 @@ namespace pmr
   operator==(const memory_resource& __a, const memory_resource& __b) noexcept
   { return &__a == &__b || __a.is_equal(__b); }
 
+#if __cpp_impl_three_way_comparison < 201907L
   inline bool
   operator!=(const memory_resource& __a, const memory_resource& __b) noexcept
   { return !(__a == __b); }
-
+#endif
 
   // C++17 23.12.3 Class template polymorphic_allocator
   template<typename _Tp>
@@ -362,12 +363,13 @@ namespace pmr
 	       const polymorphic_allocator<_Tp2>& __b) noexcept
     { return *__a.resource() == *__b.resource(); }
 
+#if __cpp_impl_three_way_comparison < 201907L
   template<typename _Tp1, typename _Tp2>
     inline bool
     operator!=(const polymorphic_allocator<_Tp1>& __a,
 	       const polymorphic_allocator<_Tp2>& __b) noexcept
     { return !(__a == __b); }
-
+#endif
 
   /// Parameters for tuning a pool resource's behaviour.
   struct pool_options
diff --git a/libstdc++-v3/include/std/scoped_allocator b/libstdc++-v3/include/std/scoped_allocator
index 8b886627749..969b6d8e8c2 100644
--- a/libstdc++-v3/include/std/scoped_allocator
+++ b/libstdc++-v3/include/std/scoped_allocator
@@ -500,12 +500,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION
           && __a._M_inner == __b._M_inner;
     }
 
+#if __cpp_impl_three_way_comparison < 201907L
   /// @related std::scoped_allocator_adaptor
   template <typename _OutA1, typename _OutA2, typename... _InA>
     inline bool
     operator!=(const scoped_allocator_adaptor<_OutA1, _InA...>& __a,
                const scoped_allocator_adaptor<_OutA2, _InA...>& __b) noexcept
     { return !(__a == __b); }
+#endif
 
   /// @}


More information about the Libstdc++-cvs mailing list