[libcxx-commits] [libcxx] [libc++][NFC] Remove `__weak_result_type<F&>` partial specializations (PR #169969)

A. Jiang via libcxx-commits libcxx-commits at lists.llvm.org
Fri Nov 28 18:43:29 PST 2025


https://github.com/frederick-vs-ja created https://github.com/llvm/llvm-project/pull/169969

Currently, libc++ defines partial specializations of `__weak_result_type` for function lvalue references. However, they can never be validly used.

`__weak_result_type` is only used as base classes of these classes:
- `reference_wrapper`, where it's already invalid to instantiate `reference_wrapper<F&>`;
- `__mem_fn` (the return type of `std::mem_fn`), where the template argument must be a pointer to member function type;
- `__bind_fn` (the return type of `std::bind`), where the template argument is already decayed and thus never a reference.

So `__weak_result_type<F&>` is useless and should probably be removed.

>From ec775711b9d0f84f6959fd085884d390a449d77f Mon Sep 17 00:00:00 2001
From: "A. Jiang" <de34 at live.cn>
Date: Sat, 29 Nov 2025 10:41:36 +0800
Subject: [PATCH] [libc++][NFC] Remove `__weak_result_type<F&>` partial
 specializations

Currently, libc++ defines partial specializations of
`__weak_result_type` for function lvalue references. However, they can
never be validly used.

`__weak_result_type` is only used as base classes of these classes:
- `reference_wrapper`, where it's already invalid to instantiate
`reference_wrapper<F&>`;
- `__mem_fn` (the return type of `std::mem_fn`), where the template
argument must be a pointer to member function type;
- `__bind_fn` (the return type of `std::bind`), where the template
argument is already decayed and thus never a reference.

So `__weak_result_type<F&>` is useless and should probably be removed.
---
 .../include/__functional/weak_result_type.h   | 20 -------------------
 1 file changed, 20 deletions(-)

diff --git a/libcxx/include/__functional/weak_result_type.h b/libcxx/include/__functional/weak_result_type.h
index 4232bdc69dd00..7b898ecd66461 100644
--- a/libcxx/include/__functional/weak_result_type.h
+++ b/libcxx/include/__functional/weak_result_type.h
@@ -97,13 +97,6 @@ struct __weak_result_type<_Rp()> {
 #endif
 };
 
-template <class _Rp>
-struct __weak_result_type<_Rp (&)()> {
-#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
-  using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
-#endif
-};
-
 template <class _Rp>
 struct __weak_result_type<_Rp (*)()> {
 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
@@ -116,9 +109,6 @@ struct __weak_result_type<_Rp (*)()> {
 template <class _Rp, class _A1>
 struct __weak_result_type<_Rp(_A1)> : public __unary_function<_A1, _Rp> {};
 
-template <class _Rp, class _A1>
-struct __weak_result_type<_Rp (&)(_A1)> : public __unary_function<_A1, _Rp> {};
-
 template <class _Rp, class _A1>
 struct __weak_result_type<_Rp (*)(_A1)> : public __unary_function<_A1, _Rp> {};
 
@@ -142,9 +132,6 @@ struct __weak_result_type<_Rp(_A1, _A2)> : public __binary_function<_A1, _A2, _R
 template <class _Rp, class _A1, class _A2>
 struct __weak_result_type<_Rp (*)(_A1, _A2)> : public __binary_function<_A1, _A2, _Rp> {};
 
-template <class _Rp, class _A1, class _A2>
-struct __weak_result_type<_Rp (&)(_A1, _A2)> : public __binary_function<_A1, _A2, _Rp> {};
-
 template <class _Rp, class _Cp, class _A1>
 struct __weak_result_type<_Rp (_Cp::*)(_A1)> : public __binary_function<_Cp*, _A1, _Rp> {};
 
@@ -167,13 +154,6 @@ struct __weak_result_type<_Rp(_A1, _A2, _A3, _A4...)> {
 #endif
 };
 
-template <class _Rp, class _A1, class _A2, class _A3, class... _A4>
-struct __weak_result_type<_Rp (&)(_A1, _A2, _A3, _A4...)> {
-#if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)
-  using result_type _LIBCPP_NODEBUG _LIBCPP_DEPRECATED_IN_CXX17 = _Rp;
-#endif
-};
-
 template <class _Rp, class _A1, class _A2, class _A3, class... _A4>
 struct __weak_result_type<_Rp (*)(_A1, _A2, _A3, _A4...)> {
 #if _LIBCPP_STD_VER <= 17 || defined(_LIBCPP_ENABLE_CXX20_REMOVED_BINDER_TYPEDEFS)



More information about the libcxx-commits mailing list