get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/1.2/patches/2222701/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 2222701,
    "url": "http://patchwork.ozlabs.org/api/1.2/patches/2222701/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260413132631.393593-1-tkaminsk@redhat.com/",
    "project": {
        "id": 17,
        "url": "http://patchwork.ozlabs.org/api/1.2/projects/17/?format=api",
        "name": "GNU Compiler Collection",
        "link_name": "gcc",
        "list_id": "gcc-patches.gcc.gnu.org",
        "list_email": "gcc-patches@gcc.gnu.org",
        "web_url": null,
        "scm_url": null,
        "webscm_url": null,
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20260413132631.393593-1-tkaminsk@redhat.com>",
    "list_archive_url": null,
    "date": "2026-04-13T13:22:59",
    "name": "libstdc++: Avoid double indirection in function_ref when possible",
    "commit_ref": null,
    "pull_url": null,
    "state": "new",
    "archived": false,
    "hash": "803096709549c8c75e21fcc6102002a4c5faeb77",
    "submitter": {
        "id": 90409,
        "url": "http://patchwork.ozlabs.org/api/1.2/people/90409/?format=api",
        "name": "Tomasz Kaminski",
        "email": "tkaminsk@redhat.com"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260413132631.393593-1-tkaminsk@redhat.com/mbox/",
    "series": [
        {
            "id": 499704,
            "url": "http://patchwork.ozlabs.org/api/1.2/series/499704/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=499704",
            "date": "2026-04-13T13:22:59",
            "name": "libstdc++: Avoid double indirection in function_ref when possible",
            "version": 1,
            "mbox": "http://patchwork.ozlabs.org/series/499704/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/2222701/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/2222701/checks/",
    "tags": {},
    "related": [],
    "headers": {
        "Return-Path": "<gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@legolas.ozlabs.org",
            "gcc-patches@gcc.gnu.org"
        ],
        "Authentication-Results": [
            "legolas.ozlabs.org;\n\tdkim=pass (1024-bit key;\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=ES87Vxmo;\n\tdkim-atps=neutral",
            "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=2620:52:6:3111::32; helo=vm01.sourceware.org;\n envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org;\n receiver=patchwork.ozlabs.org)",
            "sourceware.org;\n\tdkim=pass (1024-bit key,\n unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256\n header.s=mimecast20190719 header.b=ES87Vxmo",
            "sourceware.org; dmarc=pass (p=quarantine dis=none)\n header.from=redhat.com",
            "sourceware.org; spf=pass smtp.mailfrom=redhat.com",
            "server2.sourceware.org;\n arc=none smtp.remote-ip=170.10.133.124"
        ],
        "Received": [
            "from vm01.sourceware.org (vm01.sourceware.org\n [IPv6:2620:52:6:3111::32])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4fvSrR41sjz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 23:27:33 +1000 (AEST)",
            "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 982214BA2E2D\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 13 Apr 2026 13:27:30 +0000 (GMT)",
            "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.133.124])\n by sourceware.org (Postfix) with ESMTP id 8D1E74BA2E0F\n for <gcc-patches@gcc.gnu.org>; Mon, 13 Apr 2026 13:26:36 +0000 (GMT)",
            "from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-578-y195D3UIN5SwJ7fnAxoTXg-1; Mon,\n 13 Apr 2026 09:26:34 -0400",
            "from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111])\n (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest\n SHA256)\n (No client certificate requested)\n by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id C75BB195608E; Mon, 13 Apr 2026 13:26:33 +0000 (UTC)",
            "from localhost (unknown [10.44.50.78])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 2CCA0180049F; Mon, 13 Apr 2026 13:26:32 +0000 (UTC)"
        ],
        "DKIM-Filter": [
            "OpenDKIM Filter v2.11.0 sourceware.org 982214BA2E2D",
            "OpenDKIM Filter v2.11.0 sourceware.org 8D1E74BA2E0F"
        ],
        "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 8D1E74BA2E0F",
        "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 8D1E74BA2E0F",
        "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776086796; cv=none;\n b=pfprIQ2MeEyDaRijNHNcjHZd0tGBj6/QTZmE30rciZ5iTN3o+Lxt/Q/+4t8xIvFwuBEy7SRSi5k+yuD8bcNoDu1/Cx3QL+9h1C6alls1emUKR+5eI2UrU5v4SA3r6X5G7QqZxoM2vqNDITshM9dnVKq+AwW70W8B2qIQsRBR7k4=",
        "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776086796; c=relaxed/simple;\n bh=PbTMT1MvmF/PI8h0XlnrzHmTkCGSth8JudFLvg/BTPg=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=fnDVm5l6qJDi3q2wosKlihURhPJzVp9kpEtDDPUrlezbeWbxJSKDJtwxlhMJ7GSHexpU0YJmguRF8oyZ9SOcXNaAwn3AdfHMqsG+/s/kyBn+LUl2WL7LUOEX7x31YcgI6JyWNhwmPj36WU/V2T8yW8mZhxEi66BsjoboXAbyE1M=",
        "ARC-Authentication-Results": "i=1; server2.sourceware.org",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com;\n s=mimecast20190719; t=1776086796;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding;\n bh=8LbGmH2opI7cyq/Bpwl8onN4OIAgI0x4YNHfurFIFm8=;\n b=ES87VxmokJol1NK0dZzk6CD0Vz1EPYOQOSRI4IN8A3CUiLtQvjsqUPXCRinAfUf3wphQ+s\n N+OAkNjq+GXwrQCxNqqoS+VMt8YFyl+2hWtMHvQkYRYJnEtNQCg7GtKhVqPLVLoP182U8Q\n 35IwwLyZYMpLWTORNWgj8NdQCaKSh6Q=",
        "X-MC-Unique": "y195D3UIN5SwJ7fnAxoTXg-1",
        "X-Mimecast-MFC-AGG-ID": "y195D3UIN5SwJ7fnAxoTXg_1776086794",
        "From": "=?utf-8?q?Tomasz_Kami=C5=84ski?= <tkaminsk@redhat.com>",
        "To": "libstdc++@gcc.gnu.org,\n\tgcc-patches@gcc.gnu.org",
        "Subject": "[PATCH] libstdc++: Avoid double indirection in function_ref when\n possible",
        "Date": "Mon, 13 Apr 2026 15:22:59 +0200",
        "Message-ID": "<20260413132631.393593-1-tkaminsk@redhat.com>",
        "MIME-Version": "1.0",
        "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.111",
        "X-Mimecast-Spam-Score": "0",
        "X-Mimecast-MFC-PROC-ID": "3lF4BOK5IMDArH_6cjcdo9Yx7LcKwW3OZ1Ku2Lbge6M_1776086794",
        "X-Mimecast-Originator": "redhat.com",
        "Content-Transfer-Encoding": "8bit",
        "content-type": "text/plain; charset=\"US-ASCII\"; x-default=true",
        "X-BeenThere": "gcc-patches@gcc.gnu.org",
        "X-Mailman-Version": "2.1.30",
        "Precedence": "list",
        "List-Id": "Gcc-patches mailing list <gcc-patches.gcc.gnu.org>",
        "List-Unsubscribe": "<https://gcc.gnu.org/mailman/options/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe>",
        "List-Archive": "<https://gcc.gnu.org/pipermail/gcc-patches/>",
        "List-Post": "<mailto:gcc-patches@gcc.gnu.org>",
        "List-Help": "<mailto:gcc-patches-request@gcc.gnu.org?subject=help>",
        "List-Subscribe": "<https://gcc.gnu.org/mailman/listinfo/gcc-patches>,\n <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe>",
        "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org"
    },
    "content": "This implements the P3961R1: Less double indirection in function_ref.\n\nThis patch uses provision provided by the paper for implementations, and\nexpands the set of the compatible signatures to include ParamType&& and ParamType,\nand by value return types that differs only in cv-qualifiers. This follows\nthe move_only_function approach from the r16-617-g708d40ff109c6e. Futhermore the\noptimization is also applied when function_ref<Ret(Args...) const> is constructed\nfrom function_ref<Ret(Args...)>, even if the underyling target is be mutated by\nthe call.\n\nThe implementations moves the _M_ptrs  members to newly defined base class\n__polyfunc::_Ref_base. This allows us to reuse existing __base_of and\n__invoker_of accessor in the implementation (after befriending them).\nThe accessors functions are also now marked as constexpr. Furthermore,\n_Ref_base default constructor initializes the _M_ptrs._M_obj to nullptr,\nand _M_init function is transfered to it, making it instantiations\nindependent from callback signature.\n\nTo check signature compatiblity required by standard for assignment,  new\n__is_funcref_assignable function is used, and _ArgsSignature and _TargetQuals\nmember typedef are defined in function_ref. To avoid confusion between adjusted\nand specified signature, _Signature typedef is removed from all wrappers, and\n__is_invoker_convertible is updated to use _Invoker::_Signature instead.\n\nPer SG-10 guidance __cpp_lib_function_ref feature test macro is updated to\n202604, differntiating from P3948R1 paper accepted at the same time.\n\n\tPR libstdc++/119126\n\nlibstdc++-v3/ChangeLog:\n\n\t* include/bits/funcwrap.h : (__polyfunc::__invoker_of):\n\tUpdated to use _Invoker::_Signature and mark as constexpr.\n\t(__polyfunc::_base_of): Mark as constexpr.\n\t(__std:::__is_function_ref_v, __polyfunc::_Ref_base)\n\t(__polyfunc::__is_funcref_assignable): Define.\n\t* include/bits/funcref_impl.h (std::function_ref): Add base class\n\tof type__polyfunc::_Ref_base. Befriend __invoker_of, __base_of,\n\t__is_invoker_convertible, __is_invoker_convertible.\n\t(function_ref::_Base): Define.\n\t(function_ref::_M_init, function_ref::_M_ptrs): Move to base class.\n\t(function_ref::function_ref(_Fn&&), function_ref::operator=): Handle\n\tspecializations of function_ref with compatible signatures.\n\t(function_ref::function_ref): Init base class before _M_invoke\n\tconsistently, and remove setting of _M_nullptr.\n\t* include/bits/cpyfunc_impl.h (copyable_function): Udpdated friend\n\tdeclarations.\n\t(copyable_function::_Signature): Remove.\n\t* include/bits/mofunc_impl.h (move_only_function): Udpdated friend\n\tdeclarations.\n\t(move_only_function::_Signature): Remove.\n\t* include/bits/version.def (function_ref): Bump to 202604.\n\t* include/bits/version.h: Regnerate.\n\t* testsuite/20_util/function_ref/cons.cc: Updated checked FTM value.\n\t* testsuite/20_util/function_ref/conv.cc: Updated test to illustrate\n\tthat double indirection is avoided.\n\t* testsuite/20_util/function_ref/dangling.cc: Test for initializing\n\tfrom function_ref with compatible signature.\n\t* testsuite/20_util/function_ref/dangling_neg.cc: Test for initializing\n\tfrom function_ref with incompatible signature.\n---\nI am using the provisions to skip indirection given by standard to full extents,\nincluding the const to non-const case, that works due refrence to reference\nsemantics:\n  std::function_ref<void()> f(x); // may mutate x\n  std::function_ref<void() const> w(f); // f is const callable\nHowever, I think this is aligned with general LEWG vote, that people should\nnot rely this sematnic.\n\nTesting on x86_64-linux. *function_ref* passed with c++26 mode and modules.\nOK for trunk when all test passes?\n\n libstdc++-v3/include/bits/cpyfunc_impl.h      |   7 +-\n libstdc++-v3/include/bits/funcref_impl.h      |  58 ++++++----\n libstdc++-v3/include/bits/funcwrap.h          |  52 ++++++++-\n libstdc++-v3/include/bits/mofunc_impl.h       |   7 +-\n libstdc++-v3/include/bits/version.def         |   3 +-\n libstdc++-v3/include/bits/version.h           |   4 +-\n .../testsuite/20_util/function_ref/cons.cc    |   2 +-\n .../testsuite/20_util/function_ref/conv.cc    | 103 ++++++++++++++----\n .../20_util/function_ref/dangling.cc          |  17 ++-\n .../20_util/function_ref/dangling_neg.cc      |   8 ++\n 10 files changed, 196 insertions(+), 65 deletions(-)",
    "diff": "diff --git a/libstdc++-v3/include/bits/cpyfunc_impl.h b/libstdc++-v3/include/bits/cpyfunc_impl.h\nindex f1918ddf87a..580295a5d63 100644\n--- a/libstdc++-v3/include/bits/cpyfunc_impl.h\n+++ b/libstdc++-v3/include/bits/cpyfunc_impl.h\n@@ -70,7 +70,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \n       using _Base = __polyfunc::_Cpy_base;\n       using _Invoker = __polyfunc::_Invoker<_Noex, _Res, _ArgTypes...>;\n-      using _Signature = _Invoker::_Signature;\n \n       template<typename _Tp>\n \tusing __callable\n@@ -252,14 +251,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n       typename _Invoker::__storage_func_t _M_invoke = nullptr;\n \n       template<typename _Func>\n-\tfriend auto&\n+\tfriend constexpr auto&\n \t__polyfunc::__invoker_of(_Func&) noexcept;\n \n       template<typename _Func>\n-\tfriend auto&\n+\tfriend constexpr auto&\n \t__polyfunc::__base_of(_Func&) noexcept;\n \n-      template<typename _Dst, typename _Src>\n+      template<typename _Src, typename _Dst>\n \tfriend consteval bool\n \t__polyfunc::__is_invoker_convertible() noexcept;\n     };\ndiff --git a/libstdc++-v3/include/bits/funcref_impl.h b/libstdc++-v3/include/bits/funcref_impl.h\nindex 9fcab570803..151f326f017 100644\n--- a/libstdc++-v3/include/bits/funcref_impl.h\n+++ b/libstdc++-v3/include/bits/funcref_impl.h\n@@ -48,6 +48,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t\t\t      noexcept(_Noex)>\n       { using type = _Ret(_Args...) noexcept(_Noex); };\n   } // namespace __polyfunc\n+\n   /// @endcond\n \n   /**\n@@ -67,13 +68,16 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n   template<typename _Res, typename... _ArgTypes, bool _Noex>\n     class function_ref<_Res(_ArgTypes...) _GLIBCXX_MOF_CV\n \t\t       noexcept(_Noex)>\n+    : __polyfunc::_Ref_base\n     {\n       static_assert(\n \t(std::__is_complete_or_unbounded(__type_identity<_ArgTypes>()) && ...),\n \t\"each parameter type must be a complete class\");\n \n+      using _Base = __polyfunc::_Ref_base;\n       using _Invoker = __polyfunc::_Invoker<_Noex, _Res, _ArgTypes...>;\n-      using _Signature = _Invoker::_Signature;\n+      using _ArgsSignature = _Res(_ArgTypes...) noexcept(_Noex);\n+      using _TargetQuals = int _GLIBCXX_MOF_CV&;\n \n       // [func.wrap.ref.ctor]/1 is-invokable-using\n       template<typename... _Tps>\n@@ -89,8 +93,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \tfunction_ref(_Fn* __fn) noexcept\n \t{\n \t  __glibcxx_assert(__fn != nullptr);\n-\t  _M_invoke = _Invoker::template _S_ptrs<_Fn*>();\n \t  _M_init(__fn);\n+\t  _M_invoke = _Invoker::template _S_ptrs<_Fn*>();\n \t}\n \n       /// Target and bound object is object referenced by parameter.\n@@ -108,21 +112,21 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t{\n \t  using _Fd = remove_cv_t<_Vt>;\n \t  if constexpr (__is_std_op_wrapper<_Fd>)\n-\t    {\n-\t      _M_invoke = _Invoker::template _S_nttp<_Fd{}>;\n-\t      _M_ptrs._M_obj = nullptr;\n-\t    }\n+\t    _M_invoke = _Invoker::template _S_nttp<_Fd{}>;\n \t  else if constexpr (requires (_ArgTypes&&... __args) {\n \t\t    _Fd::operator()(std::forward<_ArgTypes>(__args)...);\n \t\t  })\n+\t    _M_invoke = _Invoker::template _S_static<_Fd>;\n+\t  else if constexpr (__is_function_ref_v<_Fd>\n+\t       && __polyfunc::__is_invoker_convertible<_Fd, function_ref>())\n \t    {\n-\t      _M_invoke = _Invoker::template _S_static<_Fd>;\n-\t      _M_ptrs._M_obj = nullptr;\n+\t      _Base::operator=(__polyfunc::__base_of(__f));\n+\t      _M_invoke = __polyfunc::__invoker_of(__f);\n \t    }\n           else\n \t    {\n-\t      _M_invoke = _Invoker::template _S_ptrs<_Vt _GLIBCXX_MOF_CV&>();\n \t      _M_init(std::addressof(__f));\n+\t      _M_invoke = _Invoker::template _S_ptrs<_Vt _GLIBCXX_MOF_CV&>();\n \t    }\n \t}\n \n@@ -146,7 +150,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t    static_assert(__fn != nullptr);\n \n \t  _M_invoke = &_Invoker::template _S_nttp<__fn>;\n-\t  _M_ptrs._M_obj = nullptr;\n \t}\n \n       /// Target object is equivalent to std::bind_front<_fn>(std::ref(__ref)).\n@@ -162,6 +165,7 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t  if constexpr (is_pointer_v<_Fn> || is_member_pointer_v<_Fn>)\n \t    static_assert(__fn != nullptr);\n \n+\t  _M_init(std::addressof(__ref));\n \t  if constexpr (is_member_pointer_v<_Fn>\n \t\t\t  && same_as<_Td, typename __inv_unwrap<_Td>::type>)\n \t    // N.B. invoking member pointer on lvalue produces the same effects,\n@@ -169,7 +173,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t    _M_invoke = &_Invoker::template _S_bind_ptr<__fn, _Td _GLIBCXX_MOF_CV>;\n \t  else\n \t    _M_invoke = &_Invoker::template _S_bind_ref<__fn, _Td _GLIBCXX_MOF_CV&>;\n-\t  _M_init(std::addressof(__ref));\n \t}\n \n       /// Target object is equivalent to std::bind_front<_fn>(__ptr).\n@@ -185,13 +188,15 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t  if constexpr (is_member_pointer_v<_Fn>)\n \t    __glibcxx_assert(__ptr != nullptr);\n \n-\t  _M_invoke = &_Invoker::template _S_bind_ptr<__fn, _Td _GLIBCXX_MOF_CV>;\n \t  _M_init(__ptr);\n+\t  _M_invoke = &_Invoker::template _S_bind_ptr<__fn, _Td _GLIBCXX_MOF_CV>;\n \t}\n \n       template<typename _Tp>\n-\trequires (!is_same_v<_Tp, function_ref>) && (!is_pointer_v<_Tp>)\n+\trequires (!is_same_v<_Tp, function_ref>)\n+\t\t && (!is_pointer_v<_Tp>)\n \t\t && (!__is_constant_wrapper_v<_Tp>)\n+\t\t && (!__polyfunc::__is_funcref_assignable<function_ref, _Tp>())\n \tfunction_ref&\n \toperator=(_Tp) = delete;\n \n@@ -206,18 +211,23 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n       { return _M_invoke(_M_ptrs, std::forward<_ArgTypes>(__args)...); }\n \n     private:\n-      template<typename _Tp>\n-\tconstexpr void\n-\t_M_init(_Tp* __ptr) noexcept\n-\t{\n-\t  if constexpr (is_function_v<_Tp>)\n-\t    _M_ptrs._M_func = reinterpret_cast<void(*)()>(__ptr);\n-\t  else\n-\t    _M_ptrs._M_obj = __ptr;\n-\t}\n-\n       typename _Invoker::__ptrs_func_t _M_invoke;\n-      __polyfunc::_Ptrs _M_ptrs;\n+\n+      template<typename _Func>\n+\tfriend constexpr auto&\n+\t__polyfunc::__invoker_of(_Func&) noexcept;\n+\n+      template<typename _Func>\n+\tfriend constexpr auto&\n+\t__polyfunc::__base_of(_Func&) noexcept;\n+\n+      template<typename _Src, typename _Dst>\n+\tfriend consteval bool\n+\t__polyfunc::__is_invoker_convertible() noexcept;\n+\n+      template<typename _Dst, typename _Src>\n+        friend consteval bool\n+        __polyfunc::__is_funcref_assignable() noexcept;\n     };\n \n #undef _GLIBCXX_MOF_CV\ndiff --git a/libstdc++-v3/include/bits/funcwrap.h b/libstdc++-v3/include/bits/funcwrap.h\nindex b835e075295..69ae0c131ef 100644\n--- a/libstdc++-v3/include/bits/funcwrap.h\n+++ b/libstdc++-v3/include/bits/funcwrap.h\n@@ -231,12 +231,12 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n      using _Invoker = _Base_invoker<_Noex, remove_cv_t<_Ret>, __param_t<_Args>...>;\n \n    template<typename _Func>\n-     auto&\n+     constexpr auto&\n      __invoker_of(_Func& __f) noexcept\n      { return __f._M_invoke; }\n \n    template<typename _Func>\n-     auto&\n+     constexpr auto&\n      __base_of(_Func& __f) noexcept\n      { return static_cast<__like_t<_Func&, typename _Func::_Base>>(__f); }\n \n@@ -244,9 +244,9 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n      consteval bool\n      __is_invoker_convertible() noexcept\n      {\n-       if constexpr (requires { typename _Src::_Signature; })\n-\t return is_convertible_v<typename _Src::_Signature,\n-\t\t\t\t typename _Dst::_Signature>;\n+       if constexpr (requires { typename _Src::_Invoker::_Signature; })\n+\t return is_convertible_v<typename _Src::_Invoker::_Signature,\n+\t\t\t\t typename _Dst::_Invoker::_Signature>;\n        else\n \t return false;\n      }\n@@ -539,6 +539,25 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n   /// @cond undocumented\n   namespace __polyfunc\n   {\n+    struct _Ref_base\n+    {\n+      template<typename _Tp>\n+\tconstexpr void\n+\t_M_init(_Tp* __ptr) noexcept\n+\t{\n+\t  if constexpr (is_function_v<_Tp>)\n+\t    _M_ptrs._M_func = reinterpret_cast<void(*)()>(__ptr);\n+\t  else\n+\t    _M_ptrs._M_obj = __ptr;\n+\t}\n+\n+      constexpr\n+      _Ref_base() noexcept\n+      { _M_ptrs._M_obj = nullptr; }\n+\n+      _Ptrs _M_ptrs;\n+    };\n+\n     template<typename _Sig>\n       struct __skip_first_arg;\n \n@@ -585,6 +604,29 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n     function_ref(constant_wrapper<__cwfn, _Fn>, _Tp&&)\n       -> function_ref<remove_pointer_t<_SignaturePtr>>;\n \n+  /// @cond undocumented\n+  template<typename _Tp>\n+    constexpr bool __is_function_ref_v = false;\n+  template<typename _Tp>\n+    constexpr bool __is_function_ref_v<function_ref<_Tp>> = true;\n+\n+  /// @cond undocumented\n+  namespace __polyfunc\n+  {\n+    template<typename _Dst, typename _Src>\n+      consteval bool\n+      __is_funcref_assignable() noexcept\n+      {\n+\tif constexpr (__is_function_ref_v<_Src>)\n+\t  if constexpr (is_convertible_v<typename _Src::_ArgsSignature*,\n+\t\t\t\t\t typename _Dst::_ArgsSignature*>)\n+\t    return is_convertible_v<typename _Dst::_TargetQuals,\n+\t\t   \t\t    typename _Src::_TargetQuals>;\n+\treturn false;\n+      }\n+  } // namespace __polyfunc\n+  /// @endcond\n+\n #endif // __glibcxx_function_ref\n \n _GLIBCXX_END_NAMESPACE_VERSION\ndiff --git a/libstdc++-v3/include/bits/mofunc_impl.h b/libstdc++-v3/include/bits/mofunc_impl.h\nindex 468e6855fc6..91a78bfca01 100644\n--- a/libstdc++-v3/include/bits/mofunc_impl.h\n+++ b/libstdc++-v3/include/bits/mofunc_impl.h\n@@ -70,7 +70,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \n       using _Base = __polyfunc::_Mo_base;\n       using _Invoker = __polyfunc::_Invoker<_Noex, _Res, _ArgTypes...>;\n-      using _Signature = _Invoker::_Signature;\n \n       template<typename _Tp>\n \tusing __callable\n@@ -236,14 +235,14 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n       typename _Invoker::__storage_func_t _M_invoke = nullptr;\n \n       template<typename _Func>\n-\tfriend auto&\n+\tfriend constexpr auto&\n \t__polyfunc::__invoker_of(_Func&) noexcept;\n \n       template<typename _Func>\n-\tfriend auto&\n+\tfriend constexpr auto&\n \t__polyfunc::__base_of(_Func&) noexcept;\n \n-      template<typename _Dst, typename _Src>\n+      template<typename _Src, typename _Dst>\n \tfriend consteval bool\n \t__polyfunc::__is_invoker_convertible() noexcept;\n     };\ndiff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def\nindex b88d9c3483f..539dc5ee4eb 100644\n--- a/libstdc++-v3/include/bits/version.def\n+++ b/libstdc++-v3/include/bits/version.def\n@@ -1962,9 +1962,10 @@ ftms = {\n   // 202306 P0792R14 function_ref: a non-owning reference to a Callable\n   // 202511 P3774R1  Rename std::nontype, and make it broadly useful\n   // 202603 P3948R1  constant_wrapper is the only tool needed for passing...\n+  // 202604 P3961R1  Less double indirection in function_ref (RU-220)\n   name = function_ref;\n   values = {\n-    v = 202603;\n+    v = 202604;\n     cxxmin = 26;\n   };\n };\ndiff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h\nindex 24ec0175e1e..57aa5baf5f9 100644\n--- a/libstdc++-v3/include/bits/version.h\n+++ b/libstdc++-v3/include/bits/version.h\n@@ -2183,9 +2183,9 @@\n \n #if !defined(__cpp_lib_function_ref)\n # if (__cplusplus >  202302L)\n-#  define __glibcxx_function_ref 202603L\n+#  define __glibcxx_function_ref 202604L\n #  if defined(__glibcxx_want_all) || defined(__glibcxx_want_function_ref)\n-#   define __cpp_lib_function_ref 202603L\n+#   define __cpp_lib_function_ref 202604L\n #  endif\n # endif\n #endif /* !defined(__cpp_lib_function_ref) */\ndiff --git a/libstdc++-v3/testsuite/20_util/function_ref/cons.cc b/libstdc++-v3/testsuite/20_util/function_ref/cons.cc\nindex e6c13e3e538..33f30099c54 100644\n--- a/libstdc++-v3/testsuite/20_util/function_ref/cons.cc\n+++ b/libstdc++-v3/testsuite/20_util/function_ref/cons.cc\n@@ -5,7 +5,7 @@\n \n #ifndef __cpp_lib_function_ref\n # error \"Feature-test macro for function_ref missing in <functional>\"\n-#elif __cpp_lib_function_ref != 202603L\n+#elif __cpp_lib_function_ref != 202604L\n # error \"Feature-test macro for function_ref has wrong value in <functional>\"\n #endif\n \ndiff --git a/libstdc++-v3/testsuite/20_util/function_ref/conv.cc b/libstdc++-v3/testsuite/20_util/function_ref/conv.cc\nindex 7606d265f98..4d772580b39 100644\n--- a/libstdc++-v3/testsuite/20_util/function_ref/conv.cc\n+++ b/libstdc++-v3/testsuite/20_util/function_ref/conv.cc\n@@ -36,8 +36,33 @@ static_assert( std::is_same_v<std::function_ref<void(int const[5])>,\n static_assert( std::is_same_v<std::function_ref<void(FuncType)>,\n \t\t\t      std::function_ref<void(FuncType*)>>);\n \n-// The C++26 [func.wrap.general] p2 does not currently cover funciton_ref,\n-// so we make extra copies of arguments.\n+// Compatible signatures per standard, function_ref is assingable\n+static_assert( std::is_assignable_v<std::function_ref<int(long) noexcept>&,\n+\t\t\t\t    std::function_ref<int(long) const noexcept>> );\n+static_assert( std::is_assignable_v<std::function_ref<int(long) const>&,\n+\t\t                    std::function_ref<int(long) const noexcept>> );\n+static_assert( std::is_assignable_v<std::function_ref<int(long)>&,\n+\t\t\t\t    std::function_ref<int(long) const noexcept>> );\n+\n+// Incompatible signatures per standard,  not assignable\n+static_assert( !std::is_assignable_v<std::function_ref<int(long) const>&,\n+\t\t\t\t     std::function_ref<int(long)>> );\n+static_assert( !std::is_assignable_v<std::function_ref<int(int)>&,\n+\t\t\t\t     std::function_ref<int(long)>> );\n+static_assert( !std::is_assignable_v<std::function_ref<long(long)>&,\n+\t\t\t\t     std::function_ref<int(long)>> );\n+static_assert( !std::is_assignable_v<std::function_ref<long(int)>&,\n+\t\t\t\t     std::function_ref<int(long)>> );\n+\n+// Implementation-specific compatible signatures, function_ref is not assingable\n+static_assert( !std::is_assignable_v<std::function_ref<int(CountedArg)>&,\n+\t\t\t\t     std::function_ref<int(CountedArg&&)>> );\n+static_assert( !std::is_assignable_v<std::function_ref<CountedArg()>&,\n+\t\t                     std::function_ref<const CountedArg(long)>> );\n+static_assert( !std::is_assignable_v<std::function_ref<const CountedArg()>&,\n+\t\t                     std::function_ref<CountedArg(long)>> );\n+static_assert( !std::is_assignable_v<std::function_ref<int(long) const>&,\n+\t\t                     std::function_ref<int(long)>> );\n \n void\n test01()\n@@ -54,26 +79,40 @@ test01()\n   VERIFY( r2c(c) == 2 );\n \n   std::function_ref<int(CountedArg) const> r3r(r1);\n-  VERIFY( r3r(c) == 2 );\n+  VERIFY( r3r(c) == 1 );\n   std::function_ref<int(CountedArg) const> r3m(m1);\n   VERIFY( r3m(c) == 2 );\n   std::function_ref<int(CountedArg) const> r3c(c1);\n   VERIFY( r3c(c) == 2 );\n \n-  std::function_ref<int(CountedArg)> r4r(r1);\n-  VERIFY( r4r(c) == 2 );\n-  std::function_ref<int(CountedArg)> r4m(m1);\n+  std::function_ref<int(CountedArg) noexcept> r4r(r1);\n+  VERIFY( r4r(c) == 1 );\n+  std::function_ref<int(CountedArg) noexcept> r4m(m1);\n   VERIFY( r4m(c) == 2 );\n-  std::function_ref<int(CountedArg)> r4c(c1);\n+  std::function_ref<int(CountedArg) noexcept> r4c(c1);\n   VERIFY( r4c(c) == 2 );\n \n+  std::function_ref<int(CountedArg)> r5r(r1);\n+  VERIFY( r4r(c) == 1 );\n+  std::function_ref<int(CountedArg)> r5m(m1);\n+  VERIFY( r4m(c) == 2 );\n+  std::function_ref<int(CountedArg)> r5c(c1);\n+  VERIFY( r4c(c) == 2 );\n+\n+  r3r = r1;\n+  VERIFY( r3r(c) == 1 );\n+  r4r = r1;\n+  VERIFY( r4r(c) == 1 );\n+  r5r = r1;\n+  VERIFY( r5r(c) == 1 );\n+\n   // Incompatible signatures\n-  std::function_ref<long(CountedArg) const noexcept> r5r(r1);\n-  VERIFY( r5r(c) == 2 );\n-  std::function_ref<long(CountedArg) const noexcept> r5m(m1);\n-  VERIFY( r5r(c) == 2 );\n-  std::function_ref<long(CountedArg) const noexcept> r5c(c1);\n-  VERIFY( r5r(c) == 2 );\n+  std::function_ref<long(CountedArg) const noexcept> r6r(r1);\n+  VERIFY( r6r(c) == 2 );\n+  std::function_ref<long(CountedArg) const noexcept> r6m(m1);\n+  VERIFY( r6r(c) == 2 );\n+  std::function_ref<long(CountedArg) const noexcept> r6c(c1);\n+  VERIFY( r6r(c) == 2 );\n }\n \n void\n@@ -110,7 +149,7 @@ test03()\n   // Call const overload as std::function_ref<int(CountedArg) const>\n   // inside std::function_ref<int(CountedArg)> would do.\n   std::function_ref<int(CountedArg)> r2(r1);\n-  VERIFY( r2(c) == 1002 );\n+  VERIFY( r2(c) == 1001 );\n   std::move_only_function<int(CountedArg)> m2(r1);\n   VERIFY( m2(c) == 1002 );\n \n@@ -119,7 +158,7 @@ test03()\n   std::function_ref<int(CountedArg)> r3(f);\n   VERIFY( r3(c) == 1 );\n   std::function_ref<int(CountedArg) const> r4(r3);\n-  VERIFY( r4(c) == 2 );\n+  VERIFY( r4(c) == 1 );\n   std::move_only_function<int(CountedArg) const> m4(r3);\n   VERIFY( m4(c) == 2 );\n }\n@@ -234,7 +273,7 @@ test07()\n   std::function_ref<int()> r3r(r1);\n   VERIFY( r3r() == 2 );\n   r1 = f1;\n-  VERIFY( r3r() == 1 ); // converting-constructor\n+  VERIFY( r3r() == 2 ); // converting-constructor\n \n   std::function_ref<int()> r3m(m1);\n   VERIFY( r3m() == 2 );\n@@ -263,6 +302,19 @@ test08()\n void\n test09()\n {\n+  auto f = [](CountedArg arg) noexcept { return arg.counter; };\n+  // For non-tirival types Param and Param&& are compatible.\n+  std::function_ref<int(CountedArg) const noexcept> r1(f);\n+  VERIFY( r1({}) == 1 );\n+  std::function_ref<int(CountedArg&&) const noexcept> r2(r1);\n+  VERIFY( r2({}) == 1 );\n+\n+  auto fs = [](CountedArg const& arg, std::string) noexcept { return arg.counter; };\n+  std::function_ref<int(CountedArg, std::string) const noexcept> rs1(fs);\n+  VERIFY( rs1(c, \"\") == 1 );\n+  std::function_ref<int(CountedArg, std::string&&) const noexcept> rs2(rs1);\n+  VERIFY( rs2(c, \"\") == 1 );\n+\n   // Scalar types and small trivially move constructible types are passed\n   // by value to invoker. So int&& signature is not compatible for such types.\n   auto fi = [](CountedArg const& arg, int) noexcept { return arg.counter; };\n@@ -271,11 +323,20 @@ test09()\n   std::function_ref<int(CountedArg, int&&) const noexcept> ri2(ri1);\n   VERIFY( ri2(c, 0) == 2 );\n \n-  auto fs = [](CountedArg const& arg, std::string_view) noexcept { return arg.counter; };\n-  std::function_ref<int(CountedArg, std::string_view) const noexcept> rs1(fs);\n-  VERIFY( rs1(c, \"\") == 1 );\n-  std::function_ref<int(CountedArg, std::string_view&&) const noexcept> rs2(rs1);\n-  VERIFY( rs2(c, \"\") == 2 );\n+  auto fv = [](CountedArg const& arg, std::string_view) noexcept { return arg.counter; };\n+  std::function_ref<int(CountedArg, std::string_view) const noexcept> rv1(fv);\n+  VERIFY( rv1(c, \"\") == 1 );\n+  std::function_ref<int(CountedArg, std::string_view&&) const noexcept> rv2(rv1);\n+  VERIFY( rv2(c, \"\") == 2 );\n+\n+  // CV-qual on by-value return is also ignored\n+  auto fr = [](CountedArg const& arg) noexcept { return arg; };\n+  std::function_ref<CountedArg(CountedArg) const noexcept> rr1(fr);\n+  VERIFY( rr1(c).counter == 2 );\n+  std::function_ref<const CountedArg(CountedArg) const noexcept> rr2(rr1);\n+  VERIFY( rr2(c).counter == 2 );\n+  std::function_ref<CountedArg(CountedArg)> rr3(rr2);\n+  VERIFY( rr3(c).counter == 2 );\n }\n \n int main()\ndiff --git a/libstdc++-v3/testsuite/20_util/function_ref/dangling.cc b/libstdc++-v3/testsuite/20_util/function_ref/dangling.cc\nindex 4ef5d067555..4a7b102c788 100644\n--- a/libstdc++-v3/testsuite/20_util/function_ref/dangling.cc\n+++ b/libstdc++-v3/testsuite/20_util/function_ref/dangling.cc\n@@ -1,12 +1,13 @@\n // { dg-do compile { target c++26 } }\n \n #include <functional>\n+#include <string>\n \n-template<typename F>\n-constexpr std::function_ref<int(int, int) const>\n+template<typename Signature = int(int, int) const, typename F>\n+constexpr std::function_ref<Signature>\n create(F f)\n {\n-  std::function_ref<int(int, int) const> fr(f);\n+  std::function_ref<Signature> fr(f);\n   return fr;\n }\n \n@@ -72,3 +73,13 @@ struct StaticWinsET {\n \n constexpr auto vStaticWinsET = create(StaticWinsET{});\n \n+auto func = [](std::string s) noexcept -> int\n+{ return s.size(); };\n+\n+constexpr std::function_ref<int(std::string)> stdCompatibleFRef\n+  = std::function_ref<int(std::string) const noexcept>(func);\n+constexpr std::function_ref<int(std::string&&)> implCompatible1FRef\n+  = std::function_ref<int(std::string)>(func);\n+constexpr std::function_ref<int(std::string) const> implCompatible2FRef\n+  = std::function_ref<int(std::string)>(func);\n+\ndiff --git a/libstdc++-v3/testsuite/20_util/function_ref/dangling_neg.cc b/libstdc++-v3/testsuite/20_util/function_ref/dangling_neg.cc\nindex 16033014703..4e99f82a50c 100644\n--- a/libstdc++-v3/testsuite/20_util/function_ref/dangling_neg.cc\n+++ b/libstdc++-v3/testsuite/20_util/function_ref/dangling_neg.cc\n@@ -74,3 +74,11 @@ struct InstanceWinsET {\n \n constexpr auto vInstanceWinsET = create(InstanceWinsET{}); // { dg-error \"is not a constant expression\" }\n \n+constexpr auto func = [](std::string s) noexcept -> int\n+{ return s.size(); };\n+\n+constexpr std::function_ref<int(const std::string&)> incompatible1FRef\n+  = std::function_ref<int(std::string)>(func); // { dg-error \"is not a constant expression\" }\n+constexpr std::function_ref<long(std::string)> incompatible2FRef\n+  = std::function_ref<int(std::string)>(func); // { dg-error \"is not a constant expression\" }\n+\n",
    "prefixes": []
}