Patch Detail
get:
Show a patch.
patch:
Update a patch.
put:
Update a patch.
GET /api/1.1/patches/2228026/?format=api
{ "id": 2228026, "url": "http://patchwork.ozlabs.org/api/1.1/patches/2228026/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/patch/20260424220245.853318-1-polacek@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": "<20260424220245.853318-1-polacek@redhat.com>", "date": "2026-04-24T22:02:45", "name": "c++/reflection: disallow reflecting block-scope externs (CWG 3065) [PR124756]", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "ccd86bbe775c56af804604d926e90eb22003eb65", "submitter": { "id": 14370, "url": "http://patchwork.ozlabs.org/api/1.1/people/14370/?format=api", "name": "Marek Polacek", "email": "polacek@redhat.com" }, "delegate": null, "mbox": "http://patchwork.ozlabs.org/project/gcc/patch/20260424220245.853318-1-polacek@redhat.com/mbox/", "series": [ { "id": 501406, "url": "http://patchwork.ozlabs.org/api/1.1/series/501406/?format=api", "web_url": "http://patchwork.ozlabs.org/project/gcc/list/?series=501406", "date": "2026-04-24T22:02:45", "name": "c++/reflection: disallow reflecting block-scope externs (CWG 3065) [PR124756]", "version": 1, "mbox": "http://patchwork.ozlabs.org/series/501406/mbox/" } ], "comments": "http://patchwork.ozlabs.org/api/patches/2228026/comments/", "check": "pending", "checks": "http://patchwork.ozlabs.org/api/patches/2228026/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=WbTrsRJd;\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=WbTrsRJd", "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 4g2Rms3sV6z1yHS\n\tfor <incoming@patchwork.ozlabs.org>; Sat, 25 Apr 2026 08:03:40 +1000 (AEST)", "from vm01.sourceware.org (localhost [127.0.0.1])\n\tby sourceware.org (Postfix) with ESMTP id 2AA8F4B9208C\n\tfor <incoming@patchwork.ozlabs.org>; Fri, 24 Apr 2026 22:03:38 +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 062F64BA5435\n for <gcc-patches@gcc.gnu.org>; Fri, 24 Apr 2026 22:02:59 +0000 (GMT)", "from mx-prod-mc-05.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-568-H-5EA3BTN5KVC42bXbM9YA-1; Fri,\n 24 Apr 2026 18:02: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-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS\n id 8C2E51956089\n for <gcc-patches@gcc.gnu.org>; Fri, 24 Apr 2026 22:02:50 +0000 (UTC)", "from pdp-11.lan (unknown [10.22.65.128])\n by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP\n id 016F51800348; Fri, 24 Apr 2026 22:02:49 +0000 (UTC)" ], "DKIM-Filter": [ "OpenDKIM Filter v2.11.0 sourceware.org 2AA8F4B9208C", "OpenDKIM Filter v2.11.0 sourceware.org 062F64BA5435" ], "DMARC-Filter": "OpenDMARC Filter v1.4.2 sourceware.org 062F64BA5435", "ARC-Filter": "OpenARC Filter v1.0.0 sourceware.org 062F64BA5435", "ARC-Seal": "i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1777068182; cv=none;\n b=bwhabcXv6o/HK44QKMsCTN8ZdsJFdZYsGoAV8swp6nPWY2iJqpo2b2Zt6tIG2ntXYr11a/4zCOo8UngcyjshTqLAHIpd3EJTD1CiM9gs8p4kTV8YmnqHeVZh6AdNxJGdokPYLrB/kozm3GpVAMD7VAT8RpE19FEUZHs3U0LxX9w=", "ARC-Message-Signature": "i=1; a=rsa-sha256; d=sourceware.org; s=key;\n t=1777068182; c=relaxed/simple;\n bh=w0ym5KtdZdMpiSg0zqNjR/Nja5PR5seuPKthogGeY98=;\n h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version;\n b=wvo340deoXQjjOpp1yRG56rElh2XhZ6UB83slLB8r+nxWRL7pkKLqx0q8Df4S9kHRviuWiKgIOKAP8/eVg6tNA3L7mygMEerTo7heVvMqZxQAxWOpO+vEUSnsUtzOKePjyPqifSHzWNDYHxIvuSBMxfY1HKPXTXuOy4JCL6N4yI=", "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=1777068179;\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=7BT+3Cvt9NhPgfuyx0AgZ0fJCCUwGK+zcc2KdvGeW4g=;\n b=WbTrsRJdcnJKl1ZPbX8cxNujskwN9tqITVN1pWM3cECmBmIoRB8fczBqQHxM90jztLbSeW\n bwv8GHh91dXgWkyKlmxQuXRFH24mLOjWvcdoLJc4Rg+3w9RsYy4i3qL0XnT1bIGVZ3m4xF\n sSE+tP6X7zqLNK4O6teYXPAJJ65XCus=", "X-MC-Unique": "H-5EA3BTN5KVC42bXbM9YA-1", "X-Mimecast-MFC-AGG-ID": "H-5EA3BTN5KVC42bXbM9YA_1777068170", "From": "Marek Polacek <polacek@redhat.com>", "To": "GCC Patches <gcc-patches@gcc.gnu.org>,\n\tJason Merrill <jason@redhat.com>", "Subject": "[PATCH] c++/reflection: disallow reflecting block-scope externs (CWG\n 3065) [PR124756]", "Date": "Fri, 24 Apr 2026 18:02:45 -0400", "Message-ID": "<20260424220245.853318-1-polacek@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": "Bc1EMZ05kQSEG7DcIrkHsdi4L8QFtJKILtiDzhVvHk0_1777068170", "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": "Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk?\n\n-- >8 --\nThe discussion in CWG 3065 concluded that reflection on a block-scope\nextern declaration is ill-formed. This patch makes it so, and it also\nhappens to fix a crash.\n\n\tPR c++/124756\n\ngcc/cp/ChangeLog:\n\n\t* reflect.cc (get_reflection): Give an error when taking the\n\treflection of a block-scope extern.\n\ngcc/testsuite/ChangeLog:\n\n\t* g++.dg/reflect/identifier_of3.C: Add dg-error.\n\t* g++.dg/reflect/pr123612.C: Likewise.\n\t* g++.dg/reflect/error13.C: New test.\n---\n gcc/cp/reflect.cc | 8 +++--\n gcc/testsuite/g++.dg/reflect/error13.C | 30 +++++++++++++++++++\n gcc/testsuite/g++.dg/reflect/identifier_of3.C | 17 ++++++-----\n gcc/testsuite/g++.dg/reflect/pr123612.C | 13 ++++----\n 4 files changed, 52 insertions(+), 16 deletions(-)\n create mode 100644 gcc/testsuite/g++.dg/reflect/error13.C\n\n\nbase-commit: 86964edc9964067c107a63efb957c50efa58b3a9", "diff": "diff --git a/gcc/cp/reflect.cc b/gcc/cp/reflect.cc\nindex 27e1efee106..b85315de4e3 100644\n--- a/gcc/cp/reflect.cc\n+++ b/gcc/cp/reflect.cc\n@@ -238,9 +238,13 @@ get_reflection (location_t loc, tree t, reflect_kind kind/*=REFLECT_UNDEF*/)\n \tt = dtor;\n }\n \n- /* Look through block scope externs. */\n+ /* Block-scope externs are invalid here as per CWG 3065. */\n if (VAR_OR_FUNCTION_DECL_P (t) && DECL_LOCAL_DECL_P (t))\n- t = DECL_LOCAL_DECL_ALIAS (t);\n+ {\n+ error_at (loc, \"cannot take the reflection of a block-scope extern %qE\",\n+\t\tt);\n+ return error_mark_node;\n+ }\n \n if (t == error_mark_node)\n return error_mark_node;\ndiff --git a/gcc/testsuite/g++.dg/reflect/error13.C b/gcc/testsuite/g++.dg/reflect/error13.C\nnew file mode 100644\nindex 00000000000..8d61b7f192c\n--- /dev/null\n+++ b/gcc/testsuite/g++.dg/reflect/error13.C\n@@ -0,0 +1,30 @@\n+// PR c++/124756\n+// { dg-do compile { target c++26 } }\n+// { dg-additional-options \"-freflection\" }\n+\n+template<typename T>\n+consteval void\n+f0 ()\n+{\n+ void fun(T);\n+ auto _ = ^^fun; // { dg-error \"cannot take the reflection of a block-scope extern .fun.\" }\n+ extern int arr[3];\n+ auto _ = ^^arr; // { dg-error \"cannot take the reflection of a block-scope extern .arr.\" }\n+ extern int e;\n+ auto _ = ^^e; // { dg-error \"cannot take the reflection of a block-scope extern .e.\" }\n+}\n+\n+consteval {\n+ f0<int>();\n+}\n+\n+consteval void\n+f1 ()\n+{\n+ void fun(int);\n+ auto _ = ^^fun; // { dg-error \"cannot take the reflection of a block-scope extern .fun.\" }\n+ extern int arr[3];\n+ auto _ = ^^arr; // { dg-error \"cannot take the reflection of a block-scope extern .arr.\" }\n+ extern int e;\n+ auto _ = ^^e; // { dg-error \"cannot take the reflection of a block-scope extern .e.\" }\n+}\ndiff --git a/gcc/testsuite/g++.dg/reflect/identifier_of3.C b/gcc/testsuite/g++.dg/reflect/identifier_of3.C\nindex 5383de07dd2..266b43471ae 100644\n--- a/gcc/testsuite/g++.dg/reflect/identifier_of3.C\n+++ b/gcc/testsuite/g++.dg/reflect/identifier_of3.C\n@@ -4,6 +4,7 @@\n // Test std::meta::identifier_of.\n \n #include <meta>\n+using namespace std::meta;\n \n void foo (int, int x, int y, int z);\n \n@@ -38,10 +39,10 @@ baz ()\n void foo (int w, int, int v, int z);\n int bar (int, int, int v, int z, int u);\n void qux (int, int x, int y, int z);\n- constexpr auto qux1 = parameters_of (^^qux)[0];\n- constexpr auto qux2 = parameters_of (^^qux)[1];\n- constexpr auto qux3 = parameters_of (^^qux)[2];\n- constexpr auto qux4 = parameters_of (^^qux)[3];\n+ constexpr auto qux1 = parameters_of (^^qux)[0]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n+ constexpr auto qux2 = parameters_of (^^qux)[1]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n+ constexpr auto qux3 = parameters_of (^^qux)[2]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n+ constexpr auto qux4 = parameters_of (^^qux)[3]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n static_assert (!has_identifier (qux1));\n static_assert (identifier_of (qux2) == std::string_view (\"x\"));\n static_assert (identifier_of (qux3) == std::string_view (\"y\"));\n@@ -62,10 +63,10 @@ void\n fred ()\n {\n void qux (int w, int, int v, int z);\n- constexpr auto qux1 = parameters_of (^^qux)[0];\n- constexpr auto qux2 = parameters_of (^^qux)[1];\n- constexpr auto qux3 = parameters_of (^^qux)[2];\n- constexpr auto qux4 = parameters_of (^^qux)[3];\n+ constexpr auto qux1 = parameters_of (^^qux)[0]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n+ constexpr auto qux2 = parameters_of (^^qux)[1]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n+ constexpr auto qux3 = parameters_of (^^qux)[2]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n+ constexpr auto qux4 = parameters_of (^^qux)[3]; // { dg-error \"cannot take the reflection of a block-scope extern .qux.\" }\n static_assert (identifier_of (qux1) == std::string_view (\"w\"));\n static_assert (identifier_of (qux2) == std::string_view (\"x\"));\n static_assert (!has_identifier (qux3));\ndiff --git a/gcc/testsuite/g++.dg/reflect/pr123612.C b/gcc/testsuite/g++.dg/reflect/pr123612.C\nindex 97da7bbdd0e..0dee4ed4f65 100644\n--- a/gcc/testsuite/g++.dg/reflect/pr123612.C\n+++ b/gcc/testsuite/g++.dg/reflect/pr123612.C\n@@ -3,6 +3,7 @@\n // { dg-additional-options \"-freflection\" }\n \n #include <meta>\n+using namespace std::meta;\n \n int a;\n extern int b;\n@@ -12,14 +13,14 @@ consteval auto\n bar ()\n {\n extern int a;\n- return ^^a;\n+ return ^^a;\t// { dg-error \"cannot take the reflection of a block-scope extern .a.\" }\n }\n \n consteval auto\n baz ()\n {\n extern int b;\n- return ^^b;\n+ return ^^b;\t// { dg-error \"cannot take the reflection of a block-scope extern .b.\" }\n }\n \n consteval auto\n@@ -30,10 +31,10 @@ qux ()\n static_assert (has_default_argument (parameters_of (^^foo)[2]));\n {\n extern int foo (int x, int y = 5, int z = 16);\n- static_assert (!has_default_argument (parameters_of (^^foo)[0]));\n- static_assert (has_default_argument (parameters_of (^^foo)[1]));\n- static_assert (has_default_argument (parameters_of (^^foo)[2]));\n- return ^^foo;\n+ static_assert (!has_default_argument (parameters_of (^^foo)[0])); // { dg-error \"cannot take the reflection of a block-scope extern .foo.\" }\n+ static_assert (has_default_argument (parameters_of (^^foo)[1])); // { dg-error \"cannot take the reflection of a block-scope extern .foo.\" }\n+ static_assert (has_default_argument (parameters_of (^^foo)[2])); // { dg-error \"cannot take the reflection of a block-scope extern .foo.\" }\n+ return ^^foo; // { dg-error \"cannot take the reflection of a block-scope extern .foo.\" }\n }\n }\n \n", "prefixes": [] }