[committed] libstdc++: Simplify allocator propagation helpers using 'if constexpr'

Message ID 20241203213746.506410-1-jwakely@redhat.com
State New
Headers
Series [committed] libstdc++: Simplify allocator propagation helpers using 'if constexpr' |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-arm fail Patch failed to apply
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 fail Patch failed to apply

Commit Message

Jonathan Wakely Dec. 3, 2024, 9:37 p.m. UTC
  Use diagnostic pragmas to allow using `if constexpr` in C++11 mode, so
that we don't need to use tag dispatching.

These helpers could be removed entirely by just using `if constexpr`
directly in the container member functions, but that's a slightly larger
change that can happen later.

It also looks like we could remove the __alloc_on_copy(const Alloc&)
overload, which is unused.

libstdc++-v3/ChangeLog:

	* include/bits/alloc_traits.h (__do_alloc_on_copy): Remove.
	(__do_alloc_on_move __do_alloc_on_swap): Remove.
	(__alloc_on_copy, __alloc_on_move, __alloc_on_swap): Use if
	constexpr.
---

Tested x86_64-linux. Pushed to trunk.

 libstdc++-v3/include/bits/alloc_traits.h | 56 ++----------------------
 1 file changed, 3 insertions(+), 53 deletions(-)
  

Patch

diff --git a/libstdc++-v3/include/bits/alloc_traits.h b/libstdc++-v3/include/bits/alloc_traits.h
index c64f4757d5d..76d5646afe5 100644
--- a/libstdc++-v3/include/bits/alloc_traits.h
+++ b/libstdc++-v3/include/bits/alloc_traits.h
@@ -835,20 +835,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
 #endif
 
   /// @cond undocumented
-#if __cplusplus < 201703L
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void
-    __do_alloc_on_copy(_Alloc& __one, const _Alloc& __two, true_type)
-    { __one = __two; }
-
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void
-    __do_alloc_on_copy(_Alloc&, const _Alloc&, false_type)
-    { }
-#endif
-
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wc++17-extensions" // if constexpr
   template<typename _Alloc>
     [[__gnu__::__always_inline__]]
     _GLIBCXX14_CONSTEXPR inline void
@@ -857,12 +845,8 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __traits = allocator_traits<_Alloc>;
       using __pocca =
 	typename __traits::propagate_on_container_copy_assignment::type;
-#if __cplusplus >= 201703L
       if constexpr (__pocca::value)
 	__one = __two;
-#else
-      __do_alloc_on_copy(__one, __two, __pocca());
-#endif
     }
 
   template<typename _Alloc>
@@ -874,18 +858,6 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       return __traits::select_on_container_copy_construction(__a);
     }
 
-#if __cplusplus < 201703L
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_move(_Alloc& __one, _Alloc& __two, true_type)
-    { __one = std::move(__two); }
-
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_move(_Alloc&, _Alloc&, false_type)
-    { }
-#endif
-
   template<typename _Alloc>
     [[__gnu__::__always_inline__]]
     _GLIBCXX14_CONSTEXPR inline void
@@ -894,29 +866,10 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
       using __traits = allocator_traits<_Alloc>;
       using __pocma
 	= typename __traits::propagate_on_container_move_assignment::type;
-#if __cplusplus >= 201703L
       if constexpr (__pocma::value)
 	__one = std::move(__two);
-#else
-      __do_alloc_on_move(__one, __two, __pocma());
-#endif
     }
 
-#if __cplusplus < 201703L
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_swap(_Alloc& __one, _Alloc& __two, true_type)
-    {
-      using std::swap;
-      swap(__one, __two);
-    }
-
-  template<typename _Alloc>
-    [[__gnu__::__always_inline__]]
-    inline void __do_alloc_on_swap(_Alloc&, _Alloc&, false_type)
-    { }
-#endif
-
   template<typename _Alloc>
     [[__gnu__::__always_inline__]]
     _GLIBCXX14_CONSTEXPR inline void
@@ -924,16 +877,13 @@  _GLIBCXX_BEGIN_NAMESPACE_VERSION
     {
       using __traits = allocator_traits<_Alloc>;
       using __pocs = typename __traits::propagate_on_container_swap::type;
-#if __cplusplus >= 201703L
       if constexpr (__pocs::value)
 	{
 	  using std::swap;
 	  swap(__one, __two);
 	}
-#else
-      __do_alloc_on_swap(__one, __two, __pocs());
-#endif
     }
+#pragma GCC diagnostic pop
 
   template<typename _Alloc, typename _Tp,
 	   typename _ValueT = __remove_cvref_t<typename _Alloc::value_type>,