Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2224738/?format=api
{ "id": 2224738, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2224738/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260418014405.1242458-1-ppalka@redhat.com/", "project": { "id": 17, "url": "http://patchwork.ozlabs.org/api/1.1/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 }, "msgid": "<20260418014405.1242458-1-ppalka@redhat.com>", "date": "2026-04-18T01:44:05", "name": "libstdc++: Fix constantness of engaged -> disengaged std::optional [PR124910]", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "ecdc1649ff710d5a38f357893f69c93fb1b757fe", "submitter": { "id": 78319, "url": "http://patchwork.ozlabs.org/api/1.1/people/78319/?format=api", "name": "Patrick Palka", "email": "ppalka@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260418014405.1242458-1-ppalka@redhat.com/mbox/", "series": [ { "id": 500414, "url": "http://patchwork.ozlabs.org/api/1.1/series/500414/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=500414", "date": "2026-04-18T01:44:05", "name": "libstdc++: Fix constantness of engaged -> disengaged std::optional [PR124910]", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/500414/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2224738/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2224738/checks/", "tags": {}, "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=b/tMUBz1;\n\tdkim-atps=neutral", "legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org\n (client-ip=38.145.34.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=b/tMUBz1", "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 [38.145.34.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 4fyF1Q5ZY7z1y1V\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 11:44:57 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id B638A4D108D8\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 18 Apr 2026 01:44:54 +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 C9BE34AA3971\n for <gcc-patches@gcc.gnu.org>; Sat, 18 Apr 2026 01:44:14 +0000 (GMT)", "from mail-qk1-f198.google.com (mail-qk1-f198.google.com\n [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS\n (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id\n us-mta-103-HEUh4FXYOv-MXp9PLDdbCg-1; Fri, 17 Apr 2026 21:44:12 -0400", "by mail-qk1-f198.google.com with SMTP id\n af79cd13be357-8e141739794so29474485a.2\n for <gcc-patches@gcc.gnu.org>; Fri, 17 Apr 2026 18:44:12 -0700 (PDT)", "from idea ([2600:4040:aa66:bf00:9e8e:99ff:fed1:71f])\n by smtp.gmail.com with ESMTPSA id\n af79cd13be357-8e7d3204cc6sm244288285a.0.2026.04.17.18.44.09\n (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n Fri, 17 Apr 2026 18:44:10 -0700 (PDT)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org B638A4D108D8", "OpenDKIM Filter v2.11.0 sourceware.org C9BE34AA3971" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org C9BE34AA3971", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org C9BE34AA3971", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776476654; cv=none;\n b=NHKdwgD5emWgUH+5PyRLLA6pXr2uqfDxFQnxMkXKUSdiPtSv+kDu6oQ4ar5gCF9npwBMQpOcwXIVH5onUbuV5fe6rgTnl+V0P83YWGm7rE10W8ppqQd434SquBBge7zDoPEYZ7iSxb2ES+BaLs7dh8CRYEGZ8CFiUru5Yx8utRg=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776476654; c=relaxed/simple;\n bh=9u8hS8jj+OR7lPQZ9t7VvPgXBkdwpy7rJAZZYTDlai0=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=K/ZX98gOHZfc/wr9If+Q6bjPicvBKdwd76VkE3pSsTs1ga+pH5ZDGQbZ6DVqozyunB2Mk8MXsvucLMBsk8tqoZo8jddWKfnURtK49tz/PSoj7+8Q3r9gu58xVkyhmIhbrXdxpLx0ld4kNIwto+sg91wtdcbGvS833+ymY7ZBJDA=", "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=1776476654;\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 bh=w+Iuwlx48Pca1CzhExxNK5K/0UsddBznvJ5CeK6UN10=;\n b=b/tMUBz1h+BvoEwpr0NtwdDwVC8UQdTi+wAaoI3Bhmnd/1jY81PMtqxxhBuByt0Kk+vS1F\n U9mnXlBX8y0HvzCsYMVSJAk/USfcpTes8QxWTPbRKkUV1iUzS0KX0obiL9P3ACsy08epra\n c0hiM3aFkiU0Lr3cIiH5sMNxc+BUkUU=", "X-MC-Unique": "HEUh4FXYOv-MXp9PLDdbCg-1", "X-Mimecast-MFC-AGG-ID": "HEUh4FXYOv-MXp9PLDdbCg_1776476652", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n d=1e100.net; s=20251104; t=1776476651; x=1777081451;\n h=content-transfer-encoding:mime-version:message-id:date:subject:cc\n :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n :message-id:reply-to;\n bh=w+Iuwlx48Pca1CzhExxNK5K/0UsddBznvJ5CeK6UN10=;\n b=V9gqBcWdHl0DARXrF6ngF7fzFvkxBgae/9ObO9k1aPuDCuwLkX8ohxvn9Y+M0Q+2hj\n hKyeH9nnA/KJUm4+2xUwyjaK0UFAXiZxhtdJyNlERogBWL8gK6c9gw47nRdPvCDheZZP\n vUUuDewotdjAnrjWzKGCgxhPW/RPxDIStC7FYz+LoR1dsgAPVgsokeTZOxZWUNH1r0La\n afrLs1LqQ82tM6JSBLHaL6L4mQoMA2JkhJm1SgvYjkaiM60zLgexvmPO4w+3QU8ukx62\n mCi16+5kMqneJIuTlE1gworvWEKTYw0f0E2t5ECbqvBRXLBQnUjbyavAaamLoFLOxiUn\n QOtA==", "X-Gm-Message-State": "AOJu0Yy83l2FSYx6ApyROVmhZ7Jep8FQfMsQ67K8gm3XVsjbb3uVci5y\n KiXF6Hg5+axFsvheK7e+rF2SWAfmh46hWafRrdMt55qXU3DQWuhQf/NilrUoDjef7Fxwjk0Ac9i\n iwq+fVXhHK9rrkB804VOWKgyZhelTgNNcn/BPJp5eyCG6DqZQ3zdLSi/yDtL+1e62IMlQOS0gSd\n pItqHACH0npkjGLfO84Q0XSIVAoYzhlCYw6G3KwyO0", "X-Gm-Gg": "AeBDieuNEy/NQsI5CPC0DHKAyj0OiqoLR1IPTFktuT1Eb38wURhnLvKvGdOyLwTAdyc\n ycy8Ti6mUIsqsfTKj5piGHdufvcQK3vA6NY1RmgU0UY9IEU77o6nWhts7+dPkNVzP3uAFG+X8ub\n KCXQEKYN4lszezaf9EB4NZMRUc+SrscpoAQQ21BuFzost0mqNSVIgTBE/f/8Km3kBfI9kd+PMZt\n wTrIwlox9hWcVus1wQh5V3qsP790NHJA0J02qzF38I3kcrNfWh7XmFIlSoMXVkWUb1pFRIgo/km\n LoF95wGMb369AtIT232mE4Sn9WuOHNyEVLKVNSgISNFTaw+50p0JW+HAGlE6Iwo/NYaSr0UMw1J\n 5JTVC+84cTw60GE9mI24/LUw=", "X-Received": [ "by 2002:a05:620a:462c:b0:8cd:b2cd:ed4 with SMTP id\n af79cd13be357-8e7916ad053mr480007085a.3.1776476651301;\n Fri, 17 Apr 2026 18:44:11 -0700 (PDT)", "by 2002:a05:620a:462c:b0:8cd:b2cd:ed4 with SMTP id\n af79cd13be357-8e7916ad053mr480004885a.3.1776476650615;\n Fri, 17 Apr 2026 18:44:10 -0700 (PDT)" ], "From": "Patrick Palka <ppalka@redhat.com>", "To": "gcc-patches@gcc.gnu.org", "Cc": "libstdc++@gcc.gnu.org, jason@redhat.com, Patrick Palka <ppalka@redhat.com>", "Subject": "[PATCH] libstdc++: Fix constantness of engaged -> disengaged\n std::optional [PR124910]", "Date": "Fri, 17 Apr 2026 21:44:05 -0400", "Message-ID": "<20260418014405.1242458-1-ppalka@redhat.com>", "X-Mailer": "git-send-email 2.54.0.rc1.54.g60f07c4f5c", "MIME-Version": "1.0", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "wBlm3vJFFLIaEpZMiUvnwfTFTMe6d33QFiZkQ6o5fx4_1776476652", "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": "Tested on x86_64-pc-linux-gnu, does this look OK for trunk? Perhaps\nbackports as well?\n\n-- >8 --\n\nWe implement std::optional<T> for trivially destructible T as a union\nwith an empty dummy member (_M_empty) indicating the disengaged state.\nWhen we disengage such an std::optional that's already engaged we call\n_M_destroy, which clears the _M_engaged flag and invokes the contained\nobjects's destructor, ending the lifetime of the corresponding union\nmember (_M_value) and leaving the union with no active member. While\nbenign at runtime, a union subobject with no active member violates\ncore constant expression requirements. Consequently the resulting\nvalue can't be used as a constant initializer, which Clang and recent\nGCC (r16-3022) correctly diagnose.\n\nTo fix this, this patch makes _M_destroy activate the _M_empty union\nmember after ending the destroying and deactivating _M_value. We use\nstd::construct_at instead of simple assignment to work around a front\nend bug (see comment #6 of the PR).\n\n\tPR c++/124910\n\nlibstdc++-v3/ChangeLog:\n\n\t* include/std/optional (_Optional_payload_base::_M_destroy):\n\tDuring constant evaluation, after invoking destructor of\n\t_M_value, call construct_at to activate _M_empty.\n\t* testsuite/20_util/optional/constexpr/124910.cc: New test.\n---\n libstdc++-v3/include/std/optional | 2 +\n .../20_util/optional/constexpr/124910.cc | 63 +++++++++++++++++++\n 2 files changed, 65 insertions(+)\n create mode 100644 libstdc++-v3/testsuite/20_util/optional/constexpr/124910.cc", "diff": "diff --git a/libstdc++-v3/include/std/optional b/libstdc++-v3/include/std/optional\nindex 0f4cf0bd1ef6..0524222eab97 100644\n--- a/libstdc++-v3/include/std/optional\n+++ b/libstdc++-v3/include/std/optional\n@@ -321,6 +321,8 @@ _GLIBCXX_BEGIN_NAMESPACE_VERSION\n {\n \t_M_engaged = false;\n \t_M_payload._M_value.~_Stored_type();\n+\tif (std::__is_constant_evaluated())\n+\t std::construct_at(std::__addressof(_M_payload._M_empty));\n }\n \n #if __cplusplus >= 202002L\ndiff --git a/libstdc++-v3/testsuite/20_util/optional/constexpr/124910.cc b/libstdc++-v3/testsuite/20_util/optional/constexpr/124910.cc\nnew file mode 100644\nindex 000000000000..f7facdec020d\n--- /dev/null\n+++ b/libstdc++-v3/testsuite/20_util/optional/constexpr/124910.cc\n@@ -0,0 +1,63 @@\n+// { dg-do compile { target c++20 } }\n+\n+// PR124910 - bogus 'std::optional{...}' is not a constant expression error\n+// after resetting it via '= nullopt'\n+\n+#include <optional>\n+\n+struct A {\n+ constexpr A(int m) : m(m) { }\n+ int m;\n+};\n+\n+struct B {\n+ constexpr B(int m) : m(m) { }\n+ constexpr ~B() { }\n+ int m;\n+};\n+\n+static_assert( std::is_trivially_destructible_v<int> );\n+static_assert( std::is_trivially_destructible_v<A> );\n+static_assert( ! std::is_trivially_destructible_v<B> );\n+\n+template<class T>\n+void do_test() {\n+ constexpr std::optional<T> x1 = [] {\n+ std::optional<T> o = 1;\n+ o = std::nullopt;\n+ return o;\n+ }();\n+\n+ constexpr std::optional<T> x2 = [] {\n+ std::optional<T> o = 1;\n+ o.reset();\n+ return o;\n+ }();\n+\n+ constexpr std::optional<T> x3 = [] {\n+ std::optional<T> o1 = 1;\n+ std::optional<long> o2;\n+ o1 = o2;\n+ return o1;\n+ }();\n+\n+ constexpr std::optional<T> x4 = [] {\n+ std::optional<T> o1 = 1;\n+ std::optional<long> o2;\n+ o1 = std::move(o2);\n+ return o1;\n+ }();\n+\n+ constexpr std::optional<T> x5 = [] {\n+ std::optional<T> o1 = 1;\n+ std::optional<T> o2;\n+ std::swap(o1, o2);\n+ return o1;\n+ }();\n+}\n+\n+int main() {\n+ do_test<int>();\n+ do_test<A>();\n+ do_test<B>();\n+}\n", "prefixes": [] }