Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/patches/2223089/?format=api
{ "id": 2223089, "url": "http://patchwork.ozlabs.org/api/patches/2223089/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260414122421.731053-1-tkaminsk@redhat.com/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/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": "<20260414122421.731053-1-tkaminsk@redhat.com>", "list_archive_url": null, "date": "2026-04-14T12:21:58", "name": "[committed,v3] libstdc++: Runtime fallback for constant_wrapper subscript and call operators.", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "6330f9ba178700124cd6c54c9722d015da914b1a", "submitter": { "id": 90409, "url": "http://patchwork.ozlabs.org/api/people/90409/?format=api", "name": "Tomasz Kaminski", "email": "tkaminsk@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260414122421.731053-1-tkaminsk@redhat.com/mbox/", "series": [ { "id": 499828, "url": "http://patchwork.ozlabs.org/api/series/499828/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=499828", "date": "2026-04-14T12:21:58", "name": "[committed,v3] libstdc++: Runtime fallback for constant_wrapper subscript and call operators.", "version": 3, "mbox": "http://patchwork.ozlabs.org/series/499828/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2223089/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2223089/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=fWYMcDB2;\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=fWYMcDB2", "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.129.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 4fw3Pt68JFz1y2d\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 22:25:05 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 6FD344BA2E11\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 14 Apr 2026 12:25:03 +0000 (GMT)", "from us-smtp-delivery-124.mimecast.com\n (us-smtp-delivery-124.mimecast.com [170.10.129.124])\n by sourceware.org (Postfix) with ESMTP id 175BA4BA2E39\n for <gcc-patches@gcc.gnu.org>; Tue, 14 Apr 2026 12:24:28 +0000 (GMT)", "from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com\n (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by\n relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3,\n cipher=TLS_AES_256_GCM_SHA384) id us-mta-501-7DlgpJ4FPO6wg9zz1KtJIQ-1; Tue,\n 14 Apr 2026 08:24:24 -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-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 9EC671800742; Tue, 14 Apr 2026 12:24:23 +0000 (UTC)", "from localhost (unknown [10.44.33.215])\n by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 2472E1800240; Tue, 14 Apr 2026 12:24:22 +0000 (UTC)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 6FD344BA2E11", "OpenDKIM Filter v2.11.0 sourceware.org 175BA4BA2E39" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 175BA4BA2E39", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 175BA4BA2E39", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776169468; cv=none;\n b=C1ZS6ncYEWBhgArp8SXSpxQCNNr0+5e4k0J379pr4mElXzgL5DloYRUXIq/UR+hYwMA7zmHUux+AlTLEGDatn/px+J6/zvbI7PVYdEIKWw5JboB2P0MY3MWXsLJiz4Rq8/gRlxawPBDL1n+6VhbMsj189e01atLizwfTEMjMjxw=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776169468; c=relaxed/simple;\n bh=y93EKkQhwKSgT7lGo2KrXOlGc5huHhDTn08GKkrQmII=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=BJ78I62un1384BQoMHUnWe2U73dM0eIAsrenbne3d1FCp3Z8DcUod4+P335kMODZHv4HA9NLNk6OjGprTYEjXhOnND7lTHH8q5CRVH/Wia+Q24udv75R+xtllPmeaD4x2z/2ly3S2/yqUy81lq/ZSPl31sae7Ze3wsVY/dHOd7A=", "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=1776169467;\n h=from:from:reply-to:subject:subject:date:date:message-id:message-id:\n to:to:cc:cc:mime-version:mime-version:content-type:content-type:\n content-transfer-encoding:content-transfer-encoding:\n in-reply-to:in-reply-to:references:references;\n bh=GLYXGYpxOSrKQyGiNID2q4XKzq7mK2Nii6oidhajgwE=;\n b=fWYMcDB2NRheRQrEw/bnvdHdVSxNRfHz4qtW0M2qbjHH17PmJs/0UFlcWDF9DcPxDoUawd\n sCwL121kZ+j7Y0MGkZYY4CHgbofftrVrENXMm2SrGFLYMBTDnhCT3rBPtbNFAJKf0xH8Nh\n cr52MHYKZ1acOSAmrbAqDALPRagTfd0=", "X-MC-Unique": "7DlgpJ4FPO6wg9zz1KtJIQ-1", "X-Mimecast-MFC-AGG-ID": "7DlgpJ4FPO6wg9zz1KtJIQ_1776169463", "From": "=?utf-8?q?Tomasz_Kami=C5=84ski?= <tkaminsk@redhat.com>", "To": "libstdc++@gcc.gnu.org,\n\tgcc-patches@gcc.gnu.org", "Cc": "Jonathan Wakely <jwakely@redhat.com>", "Subject": "[committed v3] libstdc++: Runtime fallback for constant_wrapper\n subscript and call operators.", "Date": "Tue, 14 Apr 2026 14:21:58 +0200", "Message-ID": "<20260414122421.731053-1-tkaminsk@redhat.com>", "In-Reply-To": "\n <CACb0b4=tyrOz==Vb1+ed7OaShtHoj_Qr2_fw-Jd_LhSj_5N=9Q@mail.gmail.com>", "References": "\n <CACb0b4=tyrOz==Vb1+ed7OaShtHoj_Qr2_fw-Jd_LhSj_5N=9Q@mail.gmail.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": "8lTappFps2r3NspXHHmPeXC18Fz4ylqpf_mpXyoLyW0_1776169463", "X-Mimecast-Originator": "redhat.com", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "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 P3978R3: constant_wrapper should unwrap on call and subscript.\n\nThe operator() and operator[] are now fallback to calling corresponding\noperation on value, if either arguments are not constant_wrapper like, or\nthe result of the invocation is not usable as non-type template argument\n(non-constant). The call operator is also now defined in terms of invoke,\nto support member pointers.\n\nThe noexcept specification is simplified, by observing that creating a\ndefault constructed (constant_wrapper<value(....)>{}) is never throwing\noperation. Nested requires expr is used for short-circuting, and thus\navoid checking viability of the operation on the value with\nconstant_wrapper only (see PoisonedAdd, PoisonedIndex in tests).\n\nlibstdc++-v3/ChangeLog:\n\n\t* include/bits/version.def (constant_wrapped): Updated to 202603L.\n\t* include/bits/version.h: Regenerate.\n\t* include/bits/utility.h (_CwOperators::operator())\n\t(_CwOperators:operator[]): Delete, they are now provided by...\n\t(constant_wrapper::operator(), constant_wrapper::operator[]):\n\tDefine.\n\t* testsuite/20_util/constant_wrapper/generic.cc: Add additional\n\ttest cases for invoke and subscript.\n\t* testsuite/20_util/constant_wrapper/version.cc: Update tested\n\tvalue.\n\nReviewed-by: Jonathan Wakely <jwakely@redhat.com>\nSigned-off-by: Tomasz Kamiński <tkaminsk@redhat.com>\n---\nv3 includes test for situation when expression inside template argument\n(call or subscript) exits via exception (and thus non-constexpr).\n\nTested on x86_64-linux locally. Pushed to trunk.\n\n libstdc++-v3/include/bits/utility.h | 52 ++-\n libstdc++-v3/include/bits/version.def | 4 +-\n libstdc++-v3/include/bits/version.h | 4 +-\n .../20_util/constant_wrapper/generic.cc | 342 +++++++++++++++---\n .../20_util/constant_wrapper/version.cc | 2 +-\n 5 files changed, 334 insertions(+), 70 deletions(-)", "diff": "diff --git a/libstdc++-v3/include/bits/utility.h b/libstdc++-v3/include/bits/utility.h\nindex 74ae04d6bd2..dac02e4a479 100644\n--- a/libstdc++-v3/include/bits/utility.h\n+++ b/libstdc++-v3/include/bits/utility.h\n@@ -41,6 +41,9 @@\n \n #include <type_traits>\n #include <bits/move.h>\n+#ifdef __glibcxx_constant_wrapper // C++ >= 26\n+# include <bits/invoke.h>\n+#endif\n \n namespace std _GLIBCXX_VISIBILITY(default)\n {\n@@ -342,19 +345,6 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t-> constant_wrapper<_Left::value->*(_Right::value)>\n { return {}; }\n \n- template<_ConstExprParam _Tp, _ConstExprParam... _Args>\n- constexpr auto\n- operator()(this _Tp, _Args...) noexcept\n- requires\n-\trequires(_Args...) { constant_wrapper<_Tp::value(_Args::value...)>(); }\n- { return constant_wrapper<_Tp::value(_Args::value...)>{}; }\n-\n- template<_ConstExprParam _Tp, _ConstExprParam... _Args>\n- constexpr auto\n- operator[](this _Tp, _Args...) noexcept\n-\t-> constant_wrapper<(_Tp::value[_Args::value...])>\n- { return {}; }\n-\n template<_ConstExprParam _Tp>\n constexpr auto\n operator++(this _Tp) noexcept\n@@ -453,6 +443,42 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n \t-> constant_wrapper<(value = _Right::value)>\n { return {}; }\n \n+ template<typename... _Args,\n+\t bool _ConstExprInvocable = requires {\n+\t requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);\n+\t typename constant_wrapper<std::__invoke(value, remove_cvref_t<_Args>::value...)>;\n+\t }>\n+ requires _ConstExprInvocable || is_invocable_v<const value_type&, _Args...>\n+ static constexpr decltype(auto)\n+ operator()(_Args&&... __args)\n+ noexcept(requires {\n+\trequires _ConstExprInvocable || is_nothrow_invocable_v<const value_type&, _Args...>;\n+ })\n+ {\n+\tif constexpr (_ConstExprInvocable)\n+\t return constant_wrapper<std::__invoke(value, remove_cvref_t<_Args>::value...)>{};\n+\telse\n+\t return std::__invoke(value, std::forward<_Args>(__args)...);\n+ }\n+\n+ template<typename... _Args,\n+\t bool _ConstExprSubscriptable = requires {\n+\t requires (_ConstExprParam<remove_cvref_t<_Args>> && ...);\n+\t typename constant_wrapper<value[remove_cvref_t<_Args>::value...]>;\n+\t }>\n+ requires _ConstExprSubscriptable || requires { value[std::declval<_Args>()...]; }\n+ static constexpr decltype(auto)\n+ operator[](_Args&&... __args)\n+ noexcept(requires {\n+\trequires _ConstExprSubscriptable || noexcept(value[std::declval<_Args>()...]);\n+ })\n+ {\n+\tif constexpr (_ConstExprSubscriptable)\n+\t return constant_wrapper<value[remove_cvref_t<_Args>::value...]>{};\n+\telse\n+\t return value[std::forward<_Args>(__args)...];\n+ }\n+\n constexpr\n operator decltype(value)() const noexcept\n { return value; }\ndiff --git a/libstdc++-v3/include/bits/version.def b/libstdc++-v3/include/bits/version.def\nindex 7aaf150d087..94fc1f85993 100644\n--- a/libstdc++-v3/include/bits/version.def\n+++ b/libstdc++-v3/include/bits/version.def\n@@ -408,8 +408,10 @@ ftms = {\n \n ftms = {\n name = constant_wrapper;\n+ // 202506 P2781R9 std::constexpr_wrapper \n+ // 202603 P3978R3 constant_wrapper should unwrap on call and subscript\n values = {\n- v = 202506;\n+ v = 202603;\n cxxmin = 26;\n };\n };\ndiff --git a/libstdc++-v3/include/bits/version.h b/libstdc++-v3/include/bits/version.h\nindex b247662f089..402e67580eb 100644\n--- a/libstdc++-v3/include/bits/version.h\n+++ b/libstdc++-v3/include/bits/version.h\n@@ -447,9 +447,9 @@\n \n #if !defined(__cpp_lib_constant_wrapper)\n # if (__cplusplus > 202302L)\n-# define __glibcxx_constant_wrapper 202506L\n+# define __glibcxx_constant_wrapper 202603L\n # if defined(__glibcxx_want_all) || defined(__glibcxx_want_constant_wrapper)\n-# define __cpp_lib_constant_wrapper 202506L\n+# define __cpp_lib_constant_wrapper 202603L\n # endif\n # endif\n #endif /* !defined(__cpp_lib_constant_wrapper) */\ndiff --git a/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc b/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc\nindex 1c7770d7a89..7538efead49 100644\n--- a/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc\n+++ b/libstdc++-v3/testsuite/20_util/constant_wrapper/generic.cc\n@@ -1,6 +1,8 @@\n // { dg-do run { target c++26 } }\n+#include <functional>\n #include <utility>\n #include <string_view>\n+#include <stdexcept>\n \n #include <testsuite_hooks.h>\n \n@@ -20,9 +22,9 @@ test_c_arrays()\n auto access = [](auto x, size_t i)\n { return x[i]; };\n \n- check_same(access(std::cw<x>, 0), x[0]);\n- check_same(access(std::cw<x>, 1), x[1]);\n- check_same(access(std::cw<x>, 2), x[2]);\n+ check_same(std::cw<x>[0], x[0]);\n+ check_same(std::cw<x>[1], x[1]);\n+ check_same(std::cw<x>[2], x[2]);\n \n check_same(cx[std::cw<0>], std::cw<x[0]>);\n check_same(cx[std::cw<1>], std::cw<x[1]>);\n@@ -96,76 +98,302 @@ constexpr int\n add(int i, int j)\n { return i + j; }\n \n-struct Add\n+template<bool Noexcept>\n+struct CAdd\n {\n constexpr int\n- operator()(int i, int j) const noexcept\n+ operator()(int i, int j) const noexcept(Noexcept)\n { return i + j; }\n };\n \n-constexpr void\n-test_function_object()\n+template<bool Noexcept>\n+struct RAdd\n+{\n+ int\n+ operator()(int i, int j) const noexcept(Noexcept)\n+ { return i + j; }\n+};\n+\n+struct CMixedAdd\n+{\n+ static constexpr int\n+ operator()(int i, int j)\n+ { return i + j; }\n+\n+ template <auto N1, auto N2>\n+ static constexpr int operator()\n+ (std::constant_wrapper<N1, int> i, std::constant_wrapper<N2, int> j)\n+ { return 100 + i + j; }\n+};\n+\n+struct RMixedAdd\n+{\n+ static int\n+ operator()(int i, int j)\n+ { return i + j; }\n+\n+ template <auto N1, auto N2>\n+ static int operator()\n+ (std::constant_wrapper<N1, int> i, std::constant_wrapper<N2, int> j)\n+ { return 100 + i + j; }\n+};\n+\n+template<typename T1, typename T2>\n+struct AtLeastOneInt\n+{\n+ static_assert(std::is_same_v<T1, int> || std::is_same_v<T2, int>);\n+ using type = int;\n+};\n+\n+struct PoisonedAdd\n {\n- auto check = [](auto cfo)\n+ template<typename T1, typename T2>\n+ constexpr static\n+ typename AtLeastOneInt<T1, T2>::type \n+ operator()(T1 i, T2 j) noexcept\n+ { return i + j; }\n+};\n+\n+struct MoveOnly\n+{\n+ constexpr explicit\n+ MoveOnly(int p) : v(p)\n+ { }\n+\n+ MoveOnly(MoveOnly&&) = default;\n+\n+ int v;\n+};\n+\n+struct MoveArgFunc\n+{\n+ constexpr int\n+ operator()(MoveOnly arg) const\n+ { return arg.v; }\n+};\n+\n+struct ThrowFunc\n+{\n+ static constexpr int\n+ operator()(int i, int j)\n+ {\n+ if (i < 0 || j < 0)\n+ throw std::invalid_argument(\"negative\");\n+ return i + j;\n+ }\n+};\n+\n+template<bool Constexpr, auto functor>\n+ constexpr void\n+ check_invoke()\n {\n auto ci = std::cw<2>;\n auto cj = std::cw<3>;\n+ auto cfo = std::cw<functor>;\n \n- VERIFY(cfo(ci, cj) == 5);\n- static_assert(std::same_as<decltype(cfo(ci, cj)), std::constant_wrapper<5>>);\n+ if constexpr (Constexpr)\n+ check_same(cfo(ci, cj), std::cw<5>);\n+ else\n+ check_same(cfo(ci, cj), 5);\n \n- static_assert(std::invocable<decltype(cfo), decltype(ci), decltype(cj)>);\n- static_assert(!std::invocable<decltype(cfo), int, decltype(cj)>);\n- static_assert(!std::invocable<decltype(cfo), int, int>);\n- };\n+ check_same(cfo(2, cj), 5);\n+ check_same(cfo(2, 3), 5);\n+\n+ constexpr bool Noexcept = noexcept(functor(2, 3));\n+ static_assert(noexcept(cfo(ci, cj)) == Constexpr || Noexcept);\n+ static_assert(noexcept(cfo(2, cj)) == Noexcept);\n+ static_assert(noexcept(cfo(2, 3)) == Noexcept);\n+ }\n \n- check(std::cw<Add{}>);\n- check(std::cw<[](int i, int j){ return i + j; }>);\n- check(std::cw<[](auto i, auto j){ return i + j; }>);\n+constexpr void\n+test_function_object()\n+{\n+ check_invoke<true, CAdd<true>{}>();\n+ check_invoke<true, CAdd<false>{}>();\n+ check_invoke<true, [](int i, int j) { return i + j; }>();\n+ check_invoke<true, [](auto i, auto j) noexcept { return i + j; }>();\n+ if !consteval {\n+ check_invoke<false, RAdd<true>{}>();\n+ check_invoke<false, RAdd<false>{}>();\n+ }\n+\n+ // Check if constant_wrappers are not passed to value,\n+ // if they can be unwrapped.\n+ check_invoke<true, PoisonedAdd{}>();\n+\n+ // Prefer unwrapping constant_wrappers, so calls (int, int)\n+ check_same(CMixedAdd{}(2, 3), 5);\n+ check_same(CMixedAdd{}(std::cw<2>, std::cw<3>), 105);\n+ check_same(std::cw<CMixedAdd{}>(std::cw<2>, std::cw<3>), std::cw<5>);\n+ check_invoke<true, CMixedAdd{}>();\n+ if !consteval {\n+ // Cannot return value wrapped in constant_wrapper because operator\n+ // is not constexpr, fallbacks to runtime call, that selects\n+ // (constant_wrapper, constant_wrapper) overload\n+ check_same(RMixedAdd{}(2, 3), 5);\n+ check_same(RMixedAdd{}(std::cw<2>, std::cw<3>), 105);\n+ check_same(std::cw<RMixedAdd{}>(std::cw<2>, std::cw<3>), 105);\n+ check_same(std::cw<RMixedAdd{}>(std::cw<2>, 3), 5);\n+ check_same(std::cw<RMixedAdd{}>(2, 3), 5);\n+ }\n+\n+ // Test if arguments are fowarded\n+ std::cw<MoveArgFunc{}>(MoveOnly{10});\n+\n+ // For positive arguments call do not throw, constant_wrapper type is valid.\n+ check_invoke<true, ThrowFunc{}>();\n+ // For negative arguments, the call exits via exception, and constant_wrapper \n+ // type is invalid, so we fallback to runtime.\n+ static_assert(std::is_same_v<int, decltype(std::cw<ThrowFunc{}>(std::cw<-1>, std::cw<1>))>);\n+ static_assert(!noexcept(std::cw<ThrowFunc{}>(std::cw<-1>, std::cw<1>)));\n+ try {\n+ std::cw<ThrowFunc{}>(std::cw<-1>, std::cw<1>);\n+ VERIFY(false);\n+ } catch (const std::invalid_argument&) {\n+ VERIFY(true);\n+ }\n }\n \n constexpr void\n test_function_pointer()\n {\n- auto cptr = std::cw<add>;\n- auto ci = std::cw<2>;\n- auto cj = std::cw<3>;\n+ check_invoke<true, add>();\n+}\n \n- VERIFY(cptr(ci, cj) == 5);\n- static_assert(std::same_as<decltype(cptr(ci, cj)), std::constant_wrapper<5>>);\n+template<bool Noexcept>\n+struct CIndex\n+{\n+ constexpr int\n+ operator[](int i, int j) const noexcept(Noexcept)\n+ { return i*j; }\n+};\n \n- VERIFY(cptr(2, cj) == 5);\n- static_assert(std::same_as<decltype(cptr(2, cj)), int>);\n+template<bool Noexcept>\n+struct RIndex\n+{\n+ int\n+ operator[](int i, int j) const noexcept(Noexcept)\n+ { return i*j; }\n+};\n \n- VERIFY(cptr(2, 3) == 5);\n- static_assert(std::same_as<decltype(cptr(2, 3)), int>);\n-}\n+struct CMixedIndex\n+{\n+ static constexpr int\n+ operator[](int i, int j)\n+ { return i * j; }\n+\n+ template <auto N1, auto N2>\n+ static constexpr int operator[]\n+ (std::constant_wrapper<N1, int> i, std::constant_wrapper<N2, int> j)\n+ { return 100 + i * j; }\n+};\n+\n+struct RMixedIndex\n+{\n+ static int\n+ operator[](int i, int j)\n+ { return i * j; }\n+\n+ template <auto N1, auto N2>\n+ static int operator[]\n+ (std::constant_wrapper<N1, int> i, std::constant_wrapper<N2, int> j)\n+ { return 100 + i * j; }\n+};\n \n-struct Indexable1\n+struct PoisonedIndex\n+{\n+ template<typename T1, typename T2>\n+ constexpr static\n+ typename AtLeastOneInt<T1, T2>::type \n+ operator[](T1 i, T2 j) noexcept\n+ { return i * j; }\n+};\n+\n+struct MoveArgIndex\n {\n constexpr int\n- operator[](int i, int j) const noexcept\n- { return i*j; }\n+ operator[](MoveOnly arg) const\n+ { return arg.v; }\n };\n \n-template<typename Obj, typename... Args>\n- concept indexable = requires (Obj obj, Args... args)\n+struct ThrowIndex\n+{\n+ static constexpr int\n+ operator[](int i, int j)\n {\n- obj[args...];\n- };\n+ if (i < 0 || j < 0)\n+ throw std::invalid_argument(\"negative\");\n+ return i * j;\n+ }\n+};\n+\n+template<bool Constexpr, auto index>\n+ constexpr void\n+ check_subscript()\n+ {\n+ auto ci = std::cw<2>;\n+ auto cj = std::cw<3>;\n+ auto cio = std::cw<index>;\n+\n+ if constexpr (Constexpr)\n+ check_same(cio[ci, cj], std::cw<6>);\n+ else\n+ check_same(cio[ci, cj], 6);\n+\n+ check_same(cio[2, cj], 6);\n+ check_same(cio[2, 3], 6);\n+\n+ constexpr bool Noexcept = noexcept(index[2, 3]);\n+ static_assert(noexcept(cio[ci, cj]) == Constexpr || Noexcept);\n+ static_assert(noexcept(cio[2, cj]) == Noexcept);\n+ static_assert(noexcept(cio[2, 3]) == Noexcept);\n+ }\n \n constexpr void\n test_indexable1()\n {\n- auto cind = std::cw<Indexable1{}>;\n- auto ci = std::cw<2>;\n- auto cj = std::cw<3>;\n- VERIFY(cind[ci, cj] == ci*cj);\n- static_assert(std::same_as<decltype(cind[ci, cj]), std::constant_wrapper<6>>);\n-\n- static_assert(indexable<decltype(cind), decltype(ci), decltype(cj)>);\n- static_assert(!indexable<decltype(cind), int, decltype(cj)>);\n- static_assert(!indexable<decltype(cind), int, int>);\n+ check_subscript<true, CIndex<true>{}>();\n+ check_subscript<true, CIndex<false>{}>();\n+ if !consteval {\n+ check_subscript<false, RIndex<true>{}>();\n+ check_subscript<false, RIndex<false>{}>();\n+ }\n+\n+ // Check if constant_wrappers are not passed to value,\n+ // if they can be unwrapped.\n+ check_subscript<true, PoisonedIndex{}>();\n+\n+ // Prefer unwrapping constant_wrappers, so calls (int, int)\n+ check_same(CMixedIndex{}[2, 3], 6);\n+ check_same(CMixedIndex{}[std::cw<2>, std::cw<3>], 106);\n+ check_same(std::cw<CMixedIndex{}>[std::cw<2>, std::cw<3>], std::cw<6>);\n+ check_subscript<true, CMixedIndex{}>();\n+ if !consteval {\n+ // Cannot return value wrapped in constant_wrapper because operator\n+ // is not constexpr, fallbacks to runtime call, that selects\n+ // (constant_wrapper, constant_wrapper) overload\n+ check_same(RMixedIndex{}[2, 3], 6);\n+ check_same(RMixedIndex{}[std::cw<2>, std::cw<3>], 106);\n+ check_same(std::cw<RMixedIndex{}>[std::cw<2>, std::cw<3>], 106);\n+ check_same(std::cw<RMixedIndex{}>[std::cw<2>, 3], 6);\n+ check_same(std::cw<RMixedIndex{}>[2, 3], 6);\n+ }\n+\n+ // Test if arguments are fowarded\n+ std::cw<MoveArgIndex{}>[MoveOnly{10}];\n+\n+ // For positive arguments subscript do not throw, constant_wrapper type is valid.\n+ check_subscript<true, ThrowIndex{}>();\n+ // For negative arguments, the subscript exits via exception, and constant_wrapper \n+ // type is invalid, so we fallback to runtime.\n+ static_assert(std::is_same_v<int, decltype(std::cw<ThrowIndex{}>[std::cw<-1>, std::cw<1>])>);\n+ static_assert(!noexcept(std::cw<ThrowIndex{}>[std::cw<-1>, std::cw<1>]));\n+ try {\n+ std::cw<ThrowIndex{}>[std::cw<-1>, std::cw<1>];\n+ VERIFY(false);\n+ } catch (const std::invalid_argument&) {\n+ VERIFY(true);\n+ }\n }\n \n struct Indexable2\n@@ -182,12 +410,9 @@ test_indexable2()\n auto cind = std::cw<Indexable2{}>;\n auto ci = std::cw<2>;\n auto cj = std::cw<3>;\n- VERIFY(cind[ci, cj] == ci*cj);\n- static_assert(std::same_as<decltype(cind[ci, cj]), std::constant_wrapper<6>>);\n-\n- static_assert(indexable<decltype(cind), decltype(ci), decltype(cj)>);\n- static_assert(!indexable<decltype(cind), int, decltype(cj)>);\n- static_assert(!indexable<decltype(cind), int, int>);\n+ check_same(cind[ci, cj], std::cw<6>);\n+ check_same(cind[ci, 3], 6);\n+ check_same(cind[2, 3], 6);\n }\n \n struct Indexable3\n@@ -234,10 +459,21 @@ test_member_pointer()\n check_same((&co)->*(&Divide::value), nom);\n check_same(&(co.value)->*cvalue, nom);\n \n- auto expect_unwrapped = nom / denom;\n- check_same(((&co)->*(&Divide::divide))(denom), expect_unwrapped);\n- check_same((&(co.value)->*cdiv)(denom), expect_unwrapped);\n- check_same(((&decltype(co)::value)->*cdiv)(denom), expect_unwrapped);\n+ check_same(cvalue(co), std::cw<nom>);\n+ check_same(cvalue(co.value), nom);\n+ check_same(cvalue(&co.value), nom);\n+ check_same(cvalue(std::ref(co.value)), nom);\n+\n+ auto cresult = std::cw<nom / denom>;\n+ check_same(((&co)->*(&Divide::divide))(denom), cresult.value);\n+ check_same((&(co.value)->*cdiv)(denom), cresult.value);\n+ check_same(((&decltype(co)::value)->*cdiv)(denom), cresult.value);\n+\n+ check_same(cdiv(co, std::cw<denom>), cresult); \n+ check_same(cdiv(co.value, std::cw<denom>), cresult.value); \n+ check_same(cdiv(co.value, denom), cresult.value); \n+ check_same(cdiv(&co.value, denom), cresult.value); \n+ check_same(cdiv(std::ref(co.value), denom), cresult.value); \n }\n \n struct Truthy\ndiff --git a/libstdc++-v3/testsuite/20_util/constant_wrapper/version.cc b/libstdc++-v3/testsuite/20_util/constant_wrapper/version.cc\nindex 776d80c576a..7a620994e1f 100644\n--- a/libstdc++-v3/testsuite/20_util/constant_wrapper/version.cc\n+++ b/libstdc++-v3/testsuite/20_util/constant_wrapper/version.cc\n@@ -5,7 +5,7 @@\n \n #ifndef __cpp_lib_constant_wrapper\n #error \"Feature test macro __cpp_lib_constant_wrapper is missing for <utility>\"\n-#if __cpp_lib_constant_wrapper < 202506L\n+#if __cpp_lib_constant_wrapper < 202603L\n #error \"Feature test macro __cpp_lib_constant_wrapper has the wrong value\"\n #endif\n #endif\n", "prefixes": [ "committed", "v3" ] }