{"id":2225228,"url":"http://patchwork.ozlabs.org/api/1.1/patches/2225228/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/patch/20260420164552.1598895-1-jason@redhat.com/","project":{"id":17,"url":"http://patchwork.ozlabs.org/api/1.1/projects/17/?format=json","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":"<20260420164552.1598895-1-jason@redhat.com>","date":"2026-04-20T16:45:36","name":"[pushed] c++: std::optional reset and constexpr [PR124910]","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"0a79478e25b2ea4d283b2761b833c10d58c1d28b","submitter":{"id":4337,"url":"http://patchwork.ozlabs.org/api/1.1/people/4337/?format=json","name":"Jason Merrill","email":"jason@redhat.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/gcc/patch/20260420164552.1598895-1-jason@redhat.com/mbox/","series":[{"id":500638,"url":"http://patchwork.ozlabs.org/api/1.1/series/500638/?format=json","web_url":"http://patchwork.ozlabs.org/project/gcc/list/?series=500638","date":"2026-04-20T16:45:36","name":"[pushed] c++: std::optional reset and constexpr [PR124910]","version":1,"mbox":"http://patchwork.ozlabs.org/series/500638/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2225228/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2225228/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=GPn6shxv;\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=GPn6shxv","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 4fzrxV4g9lz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 21 Apr 2026 02:47:09 +1000 (AEST)","from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 847F34B7A1C5\n\tfor <incoming@patchwork.ozlabs.org>; Mon, 20 Apr 2026 16:47:07 +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 9B96E4BC0577\n for <gcc-patches@gcc.gnu.org>; Mon, 20 Apr 2026 16:46:05 +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-360-SXp4UEM-OPOR2LUHYtAIVg-1; Mon,\n 20 Apr 2026 12:45:54 -0400","from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93])\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 EB0FA195608E\n for <gcc-patches@gcc.gnu.org>; Mon, 20 Apr 2026 16:45:53 +0000 (UTC)","from jason-thinkpadp1gen4i.rmtusma.csb (unknown [10.22.65.102])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 8AB2E180047F\n for <gcc-patches@gcc.gnu.org>; Mon, 20 Apr 2026 16:45:53 +0000 (UTC)"],"DKIM-Filter":["OpenDKIM Filter v2.11.0 sourceware.org 847F34B7A1C5","OpenDKIM Filter v2.11.0 sourceware.org 9B96E4BC0577"],"DMARC-Filter":"OpenDMARC Filter v1.4.2 sourceware.org 9B96E4BC0577","ARC-Filter":"OpenARC Filter v1.0.0 sourceware.org 9B96E4BC0577","ARC-Seal":"i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1776703565; cv=none;\n b=AKiFSULgj0Q8PrGbGXPgMPTg94ereCxC2tMGD0OIUxM3S/lKFDQDR0vSmJHR6i2P04c6Dh5v3ua6idw5X0vdlZaR0nFrD6oKeT7PdWgAggtzdfD30JNZDDNwrD/rYYrvdUCYUPcHqPpTU/PYbvqmPU4MyFpzm6n6g5d3zBqgy0U=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1776703565; c=relaxed/simple;\n bh=iQhU2n5jr7nlBI1JDxS+aYtHmzIu+dbehF1aC2Vrsew=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=VM52ChykJbxHJiPUw8f+/UtJqb5qH0md8XeYTJ2Rg4srb5FZZt0mXdqx8IRnsFiEipWin4JcN/fT8RyoNSX4VT1F3PMBUtELHeSB48QT4OkMIuquFUv2yQvXn+6g5s1SSvFzwJ4bXSyCA7HQPdXcp5OJqrtisN0BOF0/kIveH8M=","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=1776703565;\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=8Jf+HMVHf8dld6n71uA+QUMDzQLn1uJ/x79dD3Gan70=;\n b=GPn6shxvT517dw7i8IIgGb5wl3OQNrG/k/rl4GgMimhz6ZGQNZEn6qpSP0LYkJ9MVdBdvv\n MbRFz0562TYsSEAlU4ab6I+5hn213bLtlcjv6HuPZOwwjMEIWcuxnmJnDMuxbp1WL2DMGL\n NK2NFLVG7iyKmHiYh2Rmh05lsUBoj5I=","X-MC-Unique":"SXp4UEM-OPOR2LUHYtAIVg-1","X-Mimecast-MFC-AGG-ID":"SXp4UEM-OPOR2LUHYtAIVg_1776703554","From":"Jason Merrill <jason@redhat.com>","To":"gcc-patches@gcc.gnu.org","Subject":"[pushed] c++: std::optional reset and constexpr [PR124910]","Date":"Mon, 20 Apr 2026 12:45:36 -0400","Message-ID":"<20260420164552.1598895-1-jason@redhat.com>","MIME-Version":"1.0","X-Scanned-By":"MIMEDefang 3.4.1 on 10.30.177.93","X-Mimecast-Spam-Score":"0","X-Mimecast-MFC-PROC-ID":"5y3H57iSPdSMYoeV8zm7xLgtnQUB9-68alb2PxxsvME_1776703554","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 x86_64-pc-linux-gnu, applying to trunk.\n\n-- 8< --\n\nConstant evaluation didn't recognize that destroying _M_value made it no\nlonger the active member of the anonymous union, so we were treating the\nresult as containing an out-of-lifetime value.  Instead we should treat the\nunion as no longer having an active member.\n\n\tPR c++/124910\n\ngcc/cp/ChangeLog:\n\n\t* constexpr.cc (cxx_eval_store_expression): Ending the\n\tlifetime of the active member means no active member.\n\ngcc/testsuite/ChangeLog:\n\n\t* g++.dg/cpp2a/constexpr-union11.C: New test.\n---\n gcc/cp/constexpr.cc                           | 10 +++++++\n .../g++.dg/cpp2a/constexpr-union11.C          | 29 +++++++++++++++++++\n 2 files changed, 39 insertions(+)\n create mode 100644 gcc/testsuite/g++.dg/cpp2a/constexpr-union11.C\n\n\nbase-commit: b40bb34c3f5e9942d083efdee393c6e2d25e5981","diff":"diff --git a/gcc/cp/constexpr.cc b/gcc/cp/constexpr.cc\nindex 5b7d385fa97..a593b66dd41 100644\n--- a/gcc/cp/constexpr.cc\n+++ b/gcc/cp/constexpr.cc\n@@ -8207,6 +8207,16 @@ cxx_eval_store_expression (const constexpr_ctx *ctx, tree t,\n \t  no_zero_init = true;\n \t}\n \n+      /* Ending the lifetime of the active union member means the union no\n+\t longer has an active member.  */\n+      if (code == UNION_TYPE && refs->is_empty ()\n+\t  && TREE_CLOBBER_P (init)\n+\t  && CLOBBER_KIND (init) >= CLOBBER_OBJECT_END)\n+\t{\n+\t  vec_safe_truncate (CONSTRUCTOR_ELTS (*valp), 0);\n+\t  return void_node;\n+\t}\n+\n       ctors.safe_push (valp);\n       vec_safe_push (indexes, index);\n \ndiff --git a/gcc/testsuite/g++.dg/cpp2a/constexpr-union11.C b/gcc/testsuite/g++.dg/cpp2a/constexpr-union11.C\nnew file mode 100644\nindex 00000000000..56919715f55\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/cpp2a/constexpr-union11.C\n@@ -0,0 +1,29 @@\n+// PR c++/124910\n+// { dg-do compile { target c++20 } }\n+\n+struct nullopt_t { } nullopt;\n+using _Stored_type = int;\n+struct _Empty { };\n+struct _Optional_payload_base {\n+  union {\n+    int _M_value = 1;\n+    _Empty _M_empty;\n+  };\n+  constexpr void _M_reset() {\n+    _M_value.~_Stored_type();\n+    _M_empty = {};\n+  }\n+};\n+struct _Optional_payload : _Optional_payload_base {};\n+struct _Optional_base {\n+  _Optional_payload _M_payload;\n+};\n+struct optional : _Optional_base {\n+  constexpr void operator=(nullopt_t) { _M_payload._M_reset(); }\n+};\n+constexpr auto f() {\n+  optional result;\n+  result = nullopt;\n+  return result;\n+}\n+constexpr auto v = f();\n","prefixes":["pushed"]}