[committed] libstdc++: Skip tag dispatching for _S_relocate in C++17

Jonathan Wakely jwakely@redhat.com
Tue Nov 30 20:11:45 GMT 2021

Tested x86_64-linux, pushed to trunk.

In C++17 mode all callers of _S_relocate have already done:

  if constexpr (_S_use_relocate())

so we don't need to repeat that check and use tag dispatching to avoid
ill-formed instantiations.


	* include/bits/stl_vector.h (vector::_S_do_relocate): Remove
	C++20 constexpr specifier.
	(vector::_S_relocate) [__cpp_if_constexpr]: Call __relocate_a
	directly without tag dispatching.
 libstdc++-v3/include/bits/stl_vector.h | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/libstdc++-v3/include/bits/stl_vector.h b/libstdc++-v3/include/bits/stl_vector.h
index 4587757637e..36b2cff3d78 100644
--- a/libstdc++-v3/include/bits/stl_vector.h
+++ b/libstdc++-v3/include/bits/stl_vector.h
 	return _S_nothrow_relocate(__is_move_insertable<_Tp_alloc_type>{});
-      static _GLIBCXX20_CONSTEXPR pointer
+      static pointer
       _S_do_relocate(pointer __first, pointer __last, pointer __result,
 		     _Tp_alloc_type& __alloc, true_type) noexcept
 	return std::__relocate_a(__first, __last, __result, __alloc);
-      static _GLIBCXX20_CONSTEXPR pointer
+      static pointer
       _S_do_relocate(pointer, pointer, pointer __result,
 		     _Tp_alloc_type&, false_type) noexcept
       { return __result; }
       _S_relocate(pointer __first, pointer __last, pointer __result,
 		  _Tp_alloc_type& __alloc) noexcept
+#if __cpp_if_constexpr
+	// All callers have already checked _S_use_relocate() so just do it.
+	return std::__relocate_a(__first, __last, __result, __alloc);
 	using __do_it = __bool_constant<_S_use_relocate()>;
 	return _S_do_relocate(__first, __last, __result, __alloc, __do_it{});
 #endif // C++11

More information about the Gcc-patches mailing list