Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

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.

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.
@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner November 29, 2025 02:43
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Nov 29, 2025
@llvmbot
Copy link
Member

llvmbot commented Nov 29, 2025

@llvm/pr-subscribers-libcxx

Author: A. Jiang (frederick-vs-ja)

Changes

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&lt;F&amp;&gt;;
  • __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&lt;F&amp;&gt; is useless and should probably be removed.


Full diff: https://github.com/llvm/llvm-project/pull/169969.diff

1 Files Affected:

  • (modified) libcxx/include/__functional/weak_result_type.h (-20)
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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants