From 7dcfe017679f624a5ed4ab8bec56d0943bcfa10c Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tomasz=20Kami=C5=84ski?= Date: Mon, 20 Oct 2025 15:19:43 +0200 Subject: [PATCH] libstdc++: Deduce function_ref from member object pointers. Implement resolution of LWG4425. libstdc++-v3/ChangeLog: * include/bits/funcwrap.h (__polyfunc::__deduce_funcref): Adjust signature produced for member object pointers. * testsuite/20_util/function_ref/deduction.cc: Update tests. --- libstdc++-v3/include/bits/funcwrap.h | 6 ++++-- libstdc++-v3/testsuite/20_util/function_ref/deduction.cc | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/libstdc++-v3/include/bits/funcwrap.h b/libstdc++-v3/include/bits/funcwrap.h index 1a81c9a9b46..67fd591e963 100644 --- a/libstdc++-v3/include/bits/funcwrap.h +++ b/libstdc++-v3/include/bits/funcwrap.h @@ -546,8 +546,10 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION if constexpr (is_member_object_pointer_v<_Fn>) { if constexpr (is_invocable_v<_Fn, _Tr>) - // TODO Consider reporting issue to make this noexcept - return static_cast(*)()>(nullptr); + // _GLIBCXX_RESOLVE_LIB_DEFECTS + // 4425. CTAD function_ref from data member pointer should produce + // noexcept signature + return static_cast(*)() noexcept>(nullptr); } else if constexpr (requires { typename __skip_first_arg<_Fn>::type; }) return static_cast<__skip_first_arg<_Fn>::type*>(nullptr); diff --git a/libstdc++-v3/testsuite/20_util/function_ref/deduction.cc b/libstdc++-v3/testsuite/20_util/function_ref/deduction.cc index 6ed2b4e5712..b034c7af072 100644 --- a/libstdc++-v3/testsuite/20_util/function_ref/deduction.cc +++ b/libstdc++-v3/testsuite/20_util/function_ref/deduction.cc @@ -89,13 +89,13 @@ S s{}; const S cs{}; static_assert( is_same_v, s)), - function_ref> ); + function_ref> ); static_assert( is_same_v, cs)), - function_ref> ); + function_ref> ); static_assert( is_same_v, &s)), - function_ref> ); + function_ref> ); static_assert( is_same_v, &cs)), - function_ref> ); + function_ref> ); static_assert( !deductible<&S::mem, int> ); static_assert( is_same_v, s)), -- 2.47.3