Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2230122/?format=api
{ "id": 2230122, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2230122/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/afHSt5S_bry-KuXP@tucnak/", "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": "<afHSt5S_bry-KuXP@tucnak>", "date": "2026-04-29T09:43:19", "name": "c++: Delete default ctor for unions with all const members", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "e4adf0a2caacd02d47c51286cb5421a09fe37a81", "submitter": { "id": 671, "url": "http://patchwork.ozlabs.org/api/1.1/people/671/?format=api", "name": "Jakub Jelinek", "email": "jakub@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/afHSt5S_bry-KuXP@tucnak/mbox/", "series": [ { "id": 502027, "url": "http://patchwork.ozlabs.org/api/1.1/series/502027/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=502027", "date": "2026-04-29T09:43:19", "name": "c++: Delete default ctor for unions with all const members", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/502027/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2230122/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2230122/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=fY5U9Vz5;\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=fY5U9Vz5", "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 4g5C735FWzz1yHZ\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 19:43:59 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 6F25F4BA23EF\n\tfor <incoming@patchwork.ozlabs.org>; Wed, 29 Apr 2026 09:43:57 +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 A26794BA23D3\n for <gcc-patches@gcc.gnu.org>; Wed, 29 Apr 2026 09:43:25 +0000 (GMT)", "from mx-prod-mc-06.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-94-UwrdNvY7PSSusNtub9-23g-1; Wed,\n 29 Apr 2026 05:43:23 -0400", "from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com\n (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4])\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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id CDA94180034B\n for <gcc-patches@gcc.gnu.org>; Wed, 29 Apr 2026 09:43:22 +0000 (UTC)", "from tucnak.zalov.cz (unknown [10.44.34.21])\n by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with\n ESMTPS\n id 3FAC23000210; Wed, 29 Apr 2026 09:43:22 +0000 (UTC)", "from tucnak.zalov.cz (localhost [127.0.0.1])\n by tucnak.zalov.cz (8.18.1/8.18.1) with ESMTPS id 63T9hJru391829\n (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT);\n Wed, 29 Apr 2026 11:43:19 +0200", "(from jakub@localhost)\n by tucnak.zalov.cz (8.18.1/8.18.1/Submit) id 63T9hJsX391828;\n Wed, 29 Apr 2026 11:43:19 +0200" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 6F25F4BA23EF", "OpenDKIM Filter v2.11.0 sourceware.org A26794BA23D3" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org A26794BA23D3", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org A26794BA23D3", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777455805; cv=none;\n b=EpMXCs5gtJk91r6unY83uFdF1RjwkcKKiU5vASEqtkQ338i4QsRPrUBosx2yrCbzd9YyLUnzOXQ306S4Quj83Q7hQj4TbKAUSZC+oGCreSau2arBsDF0MfCMZ82MmIU9Nn8BKUvsURWnM6J0vK3GJZsLHz4WYiC2v3ys5j+nAFM=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777455805; c=relaxed/simple;\n bh=2NKLoC8YyNN9WIjAs58Wbhhq6+2Ydl9cD08MnH3sbAQ=;\n h=DKIM-Signature:Date:From:To:Subject:Message-ID:MIME-Version;\n b=xO/E9Yph+R4ZdK3h+KE+B2kkQnhs1v1RCf+dZ9srGjjcMoTQpQFSlKc7/3V3lh044geGzWfcZKDT7DK2dGUY433xlb27uYe1ozdrQrYIEbDeW09k2roWkPJwGNcQ9BgO2v0tG9/dbf9sjwJhY1Di9jxCqZFkJWF9/ZqRclnl0gc=", "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=1777455805;\n h=from:from:reply-to:reply-to:subject:subject:date:date:\n message-id:message-id:to:to:cc:cc:mime-version:mime-version:\n content-type:content-type; bh=7diZ1C2h3aFqZnJ2Uuw+/Or4AmvFE8Cpoa76yT8aup8=;\n b=fY5U9Vz5mlohdXDudWtQ7IGmsT347V4B84efQWcm0PUNjfEmEzHa5VPaksGkQhOMX0RGwW\n McaoM7nMnl5tlFewp7Tz1xfjNWRsQli4KGNeyYXaJRIs+c1wAcDkrtDj/H8KhQX/UrSZA7\n tFxRSiIj+1vgS8Z3MCkb7GxE5qTuxD8=", "X-MC-Unique": "UwrdNvY7PSSusNtub9-23g-1", "X-Mimecast-MFC-AGG-ID": "UwrdNvY7PSSusNtub9-23g_1777455803", "Date": "Wed, 29 Apr 2026 11:43:19 +0200", "From": "Jakub Jelinek <jakub@redhat.com>", "To": "Jason Merrill <jason@redhat.com>", "Cc": "gcc-patches@gcc.gnu.org", "Subject": "[PATCH] c++: Delete default ctor for unions with all const members", "Message-ID": "<afHSt5S_bry-KuXP@tucnak>", "MIME-Version": "1.0", "X-Scanned-By": "MIMEDefang 3.4.1 on 10.30.177.4", "X-Mimecast-Spam-Score": "0", "X-Mimecast-MFC-PROC-ID": "sI4XzyLM1Rfe1JZuyNlPfLpFhRJLbTCkyftpsv1gbkQ_1777455803", "X-Mimecast-Originator": "redhat.com", "Content-Type": "text/plain; charset=us-ascii", "Content-Disposition": "inline", "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>", "Reply-To": "Jakub Jelinek <jakub@redhat.com>", "Errors-To": "gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org" }, "content": "Hi!\n\nI've started looking at P3074R7/P3726R2 papers.\nThe former removes two bullets which describe when default ctor should be\ndeleted:\n- X is a union and all of its variant members are of const-qualified type (or\n possibly multi-dimensional array thereof),\n- X is a non-union class and all members of any anonymous union member are of\n const-qualified type (or possibly multi-dimensional array thereof).\nThese have been in [class.default.ctor] (or earlier in [class.ctor]) since\nC++11 till C++23, but we apparently ignore these and accept it, while\nclang++ deletes them.\n\nThe following patch implements it for C++11 (I can't find similar wording\nin C++98, but in C++98 one couldn't use NSDMIs and so gets other diagnostics\nin such cases) through C++23 inclusive, not for C++26 because P3074R7 drops\nthose.\n\nBootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?\n\n2026-04-28 Jakub Jelinek <jakub@redhat.com>\n\n\t* method.cc (walk_field_subobs): Add ALL_CONST_P argument. Determine\n\tif all variant members are const qualified. Diagnose and make deleted\n\tfor C++11 to C++23 if all anonymous union members are const qualified.\n\t(synthesized_method_walk): Diagnose and make deleted for C++11 to\n\tC++23 if all variant members of a union are const qualified.\n\n\t* g++.dg/cpp0x/defaulted70.C: New test.\n\t* g++.dg/init/pr25811.C: Expect another error for C++11 to C++23.\n\t* g++.dg/init/pr43719.C: Likewise.\n\n\n\tJakub", "diff": "--- gcc/cp/method.cc.jj\t2026-03-27 10:17:14.024332534 +0100\n+++ gcc/cp/method.cc\t2026-04-28 19:12:37.903067733 +0200\n@@ -2680,7 +2680,7 @@ walk_field_subobs (tree fields, special_\n \t\t int quals, tree *spec_p, bool *trivial_p,\n \t\t bool *deleted_p, bool *constexpr_p,\n \t\t bool diag, int flags, tsubst_flags_t complain,\n-\t\t bool dtor_from_ctor)\n+\t\t bool dtor_from_ctor, int *all_const_p)\n {\n if (!fields)\n return;\n@@ -2712,6 +2712,16 @@ walk_field_subobs (tree fields, special_\n \t && TREE_CODE (ctx) == UNION_TYPE)\n \tbreak;\n \n+ mem_type = strip_array_types (TREE_TYPE (field));\n+\n+ if (all_const_p && !ANON_AGGR_TYPE_P (mem_type))\n+\t{\n+\t if (*all_const_p == -1 && CP_TYPE_CONST_P (mem_type))\n+\t *all_const_p = 1;\n+\t else if (!CP_TYPE_CONST_P (mem_type))\n+\t *all_const_p = 0;\n+\t}\n+\n if (only_dmi_mem != no)\n \t{\n \t if (DECL_INITIAL (field))\n@@ -2721,7 +2731,6 @@ walk_field_subobs (tree fields, special_\n \t continue;\n \t}\n \n- mem_type = strip_array_types (TREE_TYPE (field));\n if (SFK_ASSIGN_P (sfk))\n \t{\n \t bool bad = true;\n@@ -2831,9 +2840,28 @@ walk_field_subobs (tree fields, special_\n \n if (ANON_AGGR_TYPE_P (mem_type))\n \t{\n+\t int *this_all_const_p = all_const_p, all_const = -1;\n+\t if (!all_const_p\n+\t && ANON_UNION_TYPE_P (mem_type)\n+\t && (sfk == sfk_constructor || sfk == sfk_inheriting_constructor)\n+\t && (cxx_dialect >= cxx11 && cxx_dialect <= cxx23))\n+\t this_all_const_p = &all_const;\n \t walk_field_subobs (TYPE_FIELDS (mem_type), sfk, fnname, quals,\n \t\t\t spec_p, trivial_p, deleted_p, constexpr_p,\n-\t\t\t diag, flags, complain, dtor_from_ctor);\n+\t\t\t diag, flags, complain, dtor_from_ctor,\n+\t\t\t this_all_const_p);\n+\t if (all_const == 1)\n+\t {\n+\t /* [class.default.ctor]/(2.6)\n+\t\t X is a non-union class and all members of any anonymous union\n+\t\t member are of const-qualified type (or array thereof). */\n+\t if (diag)\n+\t\terror_at (DECL_SOURCE_LOCATION (field),\n+\t\t\t \"all members of anonymous union member are \"\n+\t\t\t \"%<const%>-qualified\");\n+\t if (deleted_p)\n+\t\t*deleted_p = true;\n+\t }\n \t continue;\n \t}\n \n@@ -3130,14 +3158,31 @@ synthesized_method_walk (tree ctype, spe\n }\n \n /* Now handle the non-static data members. */\n+ int *all_const_p = NULL, all_const = -1;\n+ if ((sfk == sfk_constructor || sfk == sfk_inheriting_constructor)\n+ && (cxx_dialect >= cxx11 && cxx_dialect <= cxx23)\n+ && TREE_CODE (ctype) == UNION_TYPE)\n+ all_const_p = &all_const;\n walk_field_subobs (TYPE_FIELDS (ctype), sfk, fnname, quals,\n \t\t spec_p, trivial_p, deleted_p, constexpr_p,\n-\t\t diag, flags, complain, /*dtor_from_ctor*/false);\n+\t\t diag, flags, complain, /*dtor_from_ctor*/false,\n+\t\t all_const_p);\n+ if (all_const == 1)\n+ {\n+ /* [class.default.ctor]/(2.5)\n+\t X is a union and all of its variant members are of const-qualified\n+\t type (or array thereof). */\n+ if (diag)\n+\terror_at (DECL_SOURCE_LOCATION (TYPE_NAME (ctype)),\n+\t\t \"all variant members are %<const%>-qualified\");\n+ if (deleted_p)\n+\t*deleted_p = true;\n+ }\n if (SFK_CTOR_P (sfk))\n walk_field_subobs (TYPE_FIELDS (ctype), sfk_destructor,\n \t\t complete_dtor_identifier, TYPE_UNQUALIFIED,\n \t\t NULL, NULL, deleted_p, NULL,\n-\t\t false, flags, complain, /*dtor_from_ctor*/true);\n+\t\t false, flags, complain, /*dtor_from_ctor*/true, NULL);\n \n pop_scope (scope);\n \n--- gcc/testsuite/g++.dg/cpp0x/defaulted70.C.jj\t2026-04-28 19:17:37.949029070 +0200\n+++ gcc/testsuite/g++.dg/cpp0x/defaulted70.C\t2026-04-28 19:18:27.894190340 +0200\n@@ -0,0 +1,16 @@\n+// { dg-do compile { target c++11 } }\n+\n+union A { const int a = 42; const long b; } a;\n+// { dg-error \"use of deleted function 'A::A\\\\\\(\\\\\\)'\" \"\" { target c++23_down } .-1 }\n+// { dg-message \"note: 'A::A\\\\\\(\\\\\\)' is implicitly deleted because the default definition would be ill-formed:\" \"\" { target c++23_down } .-2 }\n+// { dg-error \"all variant members are 'const'-qualified\" \"\" { target c++23_down } .-3 }\n+struct B { union { const int a = 42; const long b; }; } b;\n+// { dg-error \"use of deleted function 'B::B\\\\\\(\\\\\\)'\" \"\" { target c++23_down } .-1 }\n+// { dg-message \"note: 'B::B\\\\\\(\\\\\\)' is implicitly deleted because the default definition would be ill-formed:\" \"\" { target c++23_down } .-2 }\n+// { dg-error \"all members of anonymous union member are 'const'-qualified\" \"\" { target c++23_down } .-3 }\n+union C { const int a = 42; const long b; int c; } c;\n+struct D { union { const int a = 42; const long b; int c; }; union { const int d = 42; const short e; }; } d;\n+// { dg-error \"use of deleted function 'D::D\\\\\\(\\\\\\)'\" \"\" { target c++23_down } .-1 }\n+// { dg-message \"note: 'D::D\\\\\\(\\\\\\)' is implicitly deleted because the default definition would be ill-formed:\" \"\" { target c++23_down } .-2 }\n+// { dg-error \"all members of anonymous union member are 'const'-qualified\" \"\" { target c++23_down } .-3 }\n+struct E { union { const int a = 42; const long b; int c; }; } e;\n--- gcc/testsuite/g++.dg/init/pr25811.C.jj\t2026-03-27 10:17:15.871302394 +0100\n+++ gcc/testsuite/g++.dg/init/pr25811.C\t2026-04-28 19:32:52.723677165 +0200\n@@ -126,7 +126,7 @@ struct Z // { dg-error \"deleted\" \"\" { ta\n \n union U // { dg-message \"implicitly deleted\" \"\" { target c++11 } }\n \t// { dg-error \"uninitialized\" \"\" { target c++11 } .-1 }\n-{\n+{\t// { dg-error \"all variant members are 'const'-qualified\" \"\" { target { c++11 && c++23_down } } .-2 }\n int const i; // { dg-message \"should be initialized\" }\n };\n \n--- gcc/testsuite/g++.dg/init/pr43719.C.jj\t2026-03-27 10:17:15.871302394 +0100\n+++ gcc/testsuite/g++.dg/init/pr43719.C\t2026-04-28 19:33:21.594192733 +0200\n@@ -110,7 +110,7 @@ struct Z\t\t// { dg-error \"deleted\" \"\" { t\n };\n \n union U // { dg-error \"uninitialized\" \"\" { target c++11 } }\n-{\n+{\t// { dg-error \"all variant members are 'const'-qualified\" \"\" { target { c++11 && c++23_down } } .-1 }\n int const i; // { dg-message \"should be initialized\" }\n };\n \n", "prefixes": [] }