From patchwork Wed Sep 11 11:26:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Martin X-Patchwork-Id: 1983895 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nasilyan.com header.i=@nasilyan.com header.a=rsa-sha256 header.s=tey23rxsjton5kop5bydp3vc5ylkyjkg header.b=c1VbBkDv; dkim=pass (1024-bit key; unprotected) header.d=amazonses.com header.i=@amazonses.com header.a=rsa-sha256 header.s=uku4taia5b5tsbglxyj6zym32efj7xqv header.b=LhNaH8iK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.sourceware.org (server2.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X3dZZ45lTz1y1C for ; Wed, 11 Sep 2024 21:27:02 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BA6B23858282 for ; Wed, 11 Sep 2024 11:27:00 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from a2-15.smtp-out.eu-west-1.amazonses.com (a2-15.smtp-out.eu-west-1.amazonses.com [54.240.2.15]) by sourceware.org (Postfix) with ESMTPS id 22A4B3858C98 for ; Wed, 11 Sep 2024 11:26:41 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 22A4B3858C98 Authentication-Results: sourceware.org; dmarc=fail (p=quarantine dis=none) header.from=nasilyan.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=eu-west-1.amazonses.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 22A4B3858C98 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=54.240.2.15 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726054003; cv=none; b=A0ZThmnWVUKqhnwVn0Qk3ZJhn6HgOsNwczBVW+ujk0a+DOjQaHXw1nzAYI3d6bzNIkLGGZCzFV1aOqAb0rRZSqvmiyjAF+jK7nExCZj+MF4YALlq5CgJinYUtKiYMhgEqeYaUFp6ZRMXzi1f1J3d/1hu9S8u+joisiw9cHwm5vM= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726054003; c=relaxed/simple; bh=WPa7sXsX1Cn+VAbePn0Kg7AfVGEST9FdIQIO7ksT4Pk=; h=DKIM-Signature:DKIM-Signature:Subject:From:To:Date:Mime-Version: Message-ID; b=niHh6jqDT/Fl4Z4GMuW91Cbltaipf0YADm9sL+ZtLpWEqktWvXESZcq0LIjTFlXTSIVtCuIpOt09RiWkN7ncxtQXcR0lf4gX90rigJjE2ObRGI0WoueP32veKmFlkyoec96169AKCj7wn4ssXM1cOeevMvok3ib8u33WNAO3GBo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=tey23rxsjton5kop5bydp3vc5ylkyjkg; d=nasilyan.com; t=1726053999; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id; bh=WPa7sXsX1Cn+VAbePn0Kg7AfVGEST9FdIQIO7ksT4Pk=; b=c1VbBkDvEfYhrfb40o7pcyInBGCZfyAE4n8/3ro+EPwJtpB04CzBML2KPpr6nROY aWdxx3Sjrb2wAR1CSj+S5b7CVpYqDfNxmxp/K2WuLez87uZd89pbVmuGFf56bfVlj7Z 8B7GxunxNjM9N/hg6+s7PSD5Y1wNtcl5O0loXHfU= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/simple; s=uku4taia5b5tsbglxyj6zym32efj7xqv; d=amazonses.com; t=1726053999; h=Subject:From:To:Date:Mime-Version:Content-Type:Content-Transfer-Encoding:References:Message-Id:Feedback-ID; bh=WPa7sXsX1Cn+VAbePn0Kg7AfVGEST9FdIQIO7ksT4Pk=; b=LhNaH8iKpyb6Thmc891agLAqGB/lExuH34jXoE6pNzN5DEufe1Q6Qdr+CUGQuYkG 8UrgDr7iUcUm/T3C1g+Il8F8Ie9ak7yyKioBknZp5tijqr/R276t3bRslbbwG0IFO7E J11usti9Y7t5uG0xgPjgcsaiUaYsEFjUxJ9FyDBs= Subject: [PATCH] c++: Don't ICE to build private access error message [PR116323] From: =?utf-8?q?Simon_Martin?= To: =?utf-8?q?gcc-patches=40gcc=2Egnu=2Eorg?= Date: Wed, 11 Sep 2024 11:26:39 +0000 Mime-Version: 1.0 References: <20240911112637.47636-1-simon@nasilyan.com> X-Mailer: Amazon WorkMail Thread-Index: AQHbBD1394hjlkqlRaGihDH9OeZT9g== Thread-Topic: [PATCH] c++: Don't ICE to build private access error message [PR116323] X-Original-Mailer: git-send-email 2.44.0 X-Wm-Sent-Timestamp: 1726053998 Message-ID: <01020191e0d5e45f-9128c7af-14e2-4e73-9f0d-2265af9c6c54-000000@eu-west-1.amazonses.com> Feedback-ID: ::1.eu-west-1.b24dn6frgCi6dh20skzbuMRr7UL8M6Soir/3ogtEjHQ=:AmazonSES X-SES-Outgoing: 2024.09.11-54.240.2.15 X-Spam-Status: No, score=-13.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.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~incoming=patchwork.ozlabs.org@gcc.gnu.org We currently ICE upon the following code while building the "[...] is private within this context" error message === cut here === class A { enum Enum{}; }; template class Alloc> class B : private Alloc, private A {}; template class Alloc> int B::foo (Enum m) { return 42; } === cut here === The problem is that since r11-6880, after detecting that Enum cannot be accessed in B, enforce_access will access the TYPE_BINFO of all the bases of B, which ICEs for any that is a BOUND_TEMPLATE_TEMPLATE_PARM. This patch simply skips such bases. Successfully tested on x86_64-pc-linux-gnu. PR c++/116323 gcc/cp/ChangeLog: * search.cc (get_parent_with_private_access): Only call access_in_type for RECORD_OR_UNION_TYPE_P base BINFOs. gcc/testsuite/ChangeLog: * g++.dg/template/access43.C: New test. --- gcc/cp/search.cc | 4 +++- gcc/testsuite/g++.dg/template/access43.C | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/access43.C diff --git a/gcc/cp/search.cc b/gcc/cp/search.cc index 60c30ecb881..a810cf70d6a 100644 --- a/gcc/cp/search.cc +++ b/gcc/cp/search.cc @@ -163,9 +163,11 @@ get_parent_with_private_access (tree decl, tree binfo) /* Iterate through immediate parent classes. */ for (int i = 0; BINFO_BASE_ITERATE (binfo, i, base_binfo); i++) { + tree base_binfo_type = BINFO_TYPE (base_binfo); /* This parent had private access. Therefore that's why BINFO can't access DECL. */ - if (access_in_type (BINFO_TYPE (base_binfo), decl) == ak_private) + if (RECORD_OR_UNION_TYPE_P (base_binfo_type) + && access_in_type (base_binfo_type, decl) == ak_private) return base_binfo; } diff --git a/gcc/testsuite/g++.dg/template/access43.C b/gcc/testsuite/g++.dg/template/access43.C new file mode 100644 index 00000000000..ce9e6c8fbb2 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access43.C @@ -0,0 +1,11 @@ +// PR c++/116323 +// { dg-do "compile" } +// { dg-additional-options "-Wno-template-body" } + +class A { enum Enum{}; }; + +template class Alloc> +class B : private Alloc, private A {}; + +template class Alloc> +int B::foo (Enum m) { return 42; } // { dg-error "is private" }