From patchwork Wed Sep 30 16:12:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 145025 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from vm01.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 84F224BB3B91 for ; Wed, 30 Sep 2026 16:13:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 84F224BB3B91 Authentication-Results: sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iK/dRdDu X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTP id 8A35E4BA23F4 for ; Wed, 30 Sep 2026 16:13:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8A35E4BA23F4 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8A35E4BA23F4 Authentication-Results: sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790784790; cv=none; b=UQCM18Nj5g/Wktm9hdmZiKV6R02Ow+w4i2Niw6pmOgd7H9r4gRdR5CiI61ECU6cHINeT1t9/rngYpsj3Um+uKqQ0f2pgqHLzggAVTXIii8OR0yN8BDh+JqE2IEq6rhSEDPBSc7QtE1cP9NvCy7QsZ4RdrzcAQ0Yp5n2GSGlVpaQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1790784790; c=relaxed/simple; bh=yRvs9h7fqXo7MCgCs1S0+J21mYZiS5MXY9hOIuadGxg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gwWhR9YhR1jeN8Lk2ceGA7/OFx/5N6oaIcj90sIBvDY+A8Zosex2bWO2ebOHW0cJ5WCkYlb1I/2FJFX6Kfw6FqkXTGx7khFZIGDm4p2hxQcPEhgaK4TaRnuZOIxgqzpfOtghUq3Pkuc4AIFbBkAzpuenhBkgAwOYwQtz+KvW/Y8= ARC-Authentication-Results: i=1; sourceware.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iK/dRdDu DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8A35E4BA23F4 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1790784790; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=KzZ33ExsSA/j7fZUGfwXxfFwyJbk33lrkV6Fb3o5X4E=; b=iK/dRdDuhvAXsZSY6ugXbbuofU6ke4qJvyNbOh9EpOQY47QPhdg7YK8+WF38SPdGVTNHxW hMNxi2qwOKZ+jBdTMXaVtWhwkXek8LVWbnW32HU+eJ8W/gD0y7N1UFxS9uaRgnpQbaKSW2 WAj0XzNP/XtQ1HVscgGL7zzaqatlCY8= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-711-ssfO2Tf4M66U8dwW5Nz0Gg-1; Wed, 30 Sep 2026 12:13:08 -0400 X-MC-Unique: ssfO2Tf4M66U8dwW5Nz0Gg-1 X-Mimecast-MFC-AGG-ID: ssfO2Tf4M66U8dwW5Nz0Gg_1790784787 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 9CD86184B39D for ; Wed, 30 Sep 2026 16:13:07 +0000 (UTC) Received: from mpolacek-thinkpadt14gen6.redhat.corp (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2ACFC30000E7; Wed, 30 Sep 2026 16:13:06 +0000 (UTC) From: Marek Polacek To: GCC Patches , Jason Merrill Subject: [PATCH] c++/reflection: ICE with ns splice scope in ns alias [PR127344] Date: Wed, 30 Sep 2026 12:12:54 -0400 Message-ID: <20260930161254.1080718-1-polacek@redhat.com> 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: ACbOMqTrAfjzwkbnLAPfV7CmSfZA0M7rSxmkewEEKmo_1790784787 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_PASS, SPF_NONE, TXREP shortcircuit=no autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~patchwork=sourceware.org@gcc.gnu.org Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? -- >8 -- This fixes another problem when using namespace splice scopes, this time in a namespace alias like this: template void f () { namespace A = [:ns:]; int i = A::N::x; } where we crash in make_typename_type or make_unbound_class_template because they expect a type but get a NAMESPACE_DECL built for the A alias with ORIGINAL_NAMESPACE being a SPLICE_EXPR. The decl is coming from cp_parser_namespace_alias_definition -> do_namespace_alias. We want a SPLICE_SCOPE which is a type, so build one with make_splice_scope. I considered changing cp_parser_namespace_alias_definition to build the SPLICE_SCOPE there but that brought so many other issues that it wasn't worth it. PR c++/127344 gcc/cp/ChangeLog: * parser.cc (cp_parser_lookup_name): Call make_splice_scope for dependent_namespace_p. Use the result for make_typename_type and make_unbound_class_template. gcc/testsuite/ChangeLog: * g++.dg/reflect/ns9.C: New test. --- gcc/cp/parser.cc | 17 ++++++---- gcc/testsuite/g++.dg/reflect/ns9.C | 52 ++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/g++.dg/reflect/ns9.C base-commit: f4d32f612a3c43e9d0a861b7dae7bb67139c9ab0 diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 373d3358c25..3c84f6e335f 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -35608,15 +35608,21 @@ cp_parser_lookup_name (cp_parser *parser, tree name, && dependentish_scope_p (parser->scope)) || dependent_namespace_p (parser->scope))) { + tree scope = parser->scope; + /* The make_* functions below expect something that's a type. SCOPE + is a NAMESPACE_DECL when we are dealing with a dependent namespace + alias like "namespace A = [:ns:];". */ + if (dependent_namespace_p (scope)) + scope = make_splice_scope (ORIGINAL_NAMESPACE (scope), + /*type_p=*/false); + if (tag_type) { - tree type; - /* The resolution to Core Issue 180 says that `struct A::B' should be considered a type-name, even if `A' is dependent. */ - type = make_typename_type (parser->scope, name, tag_type, - /*complain=*/tf_error); + tree type = make_typename_type (scope, name, tag_type, + /*complain=*/tf_error); if (type != error_mark_node) decl = TYPE_NAME (type); } @@ -35624,8 +35630,7 @@ cp_parser_lookup_name (cp_parser *parser, tree name, && (cp_parser_next_token_ends_template_argument_p (parser) || cp_lexer_next_token_is (parser->lexer, CPP_CLOSE_PAREN))) - decl = make_unbound_class_template (parser->scope, - name, NULL_TREE, + decl = make_unbound_class_template (scope, name, NULL_TREE, /*complain=*/tf_error); else decl = build_qualified_name (/*type=*/NULL_TREE, diff --git a/gcc/testsuite/g++.dg/reflect/ns9.C b/gcc/testsuite/g++.dg/reflect/ns9.C new file mode 100644 index 00000000000..3f2141f6271 --- /dev/null +++ b/gcc/testsuite/g++.dg/reflect/ns9.C @@ -0,0 +1,52 @@ +// PR c++/127344 +// { dg-do compile { target c++26 } } +// { dg-additional-options "-freflection" } + +template struct same_type; +template struct same_type {}; + +namespace X { struct N { static constexpr int x = 42; }; } + +template +int +f () +{ + namespace A = [:ns:]; + int i = A::N::x; + int j = [:ns:]::N::x; + return i + j; +} + +namespace N { template struct X {}; } +template class> struct S {}; + +template +void +h () +{ + namespace A = [:ns:]; + S s; +} + +namespace Y { int y = 1; void fn (); namespace N { int x = 2; } } + +template +int +k () +{ + namespace A = [:ns:]; + namespace B = A; + auto p = &A::fn; + same_type(); + auto q = &[:ns:]::fn; + same_type(); + return A::y + B::N::x; +} + +void +g () +{ + f<^^X>(); + h<^^N>(); + k<^^Y>(); +}