From patchwork Wed Jan 3 20:06:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1882206 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=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=eCnkJ4cX; 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 4T512s0YFnz23dM for ; Thu, 4 Jan 2024 07:06:59 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A53823857BA0 for ; Wed, 3 Jan 2024 20:06:57 +0000 (GMT) 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.133.124]) by sourceware.org (Postfix) with ESMTPS id B2FB53858C62 for ; Wed, 3 Jan 2024 20:06:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org B2FB53858C62 Authentication-Results: sourceware.org; dmarc=pass (p=none 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 B2FB53858C62 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704312396; cv=none; b=HoAR7J0XqDeO6MKxc8HIOiOPGpGqw0fzo+9qdjuD5HpDVXAJDKQqPgJd/5WdY1srRYGMKD5jns3Vc3c3msEv0VTezuq/o6ot3HQ3VabL8jRXWL7CeUixqjY1YSYCG5/LpPVibgI7J0mCixI2w40ATEeoCZf5oYOCHglrtOJGaJ8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1704312396; c=relaxed/simple; bh=bIGmK1J0EyS8s6Qdr1wgTP3I3K4D0H6oaF7nfdsv5SA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=FLu71Fn5oLuM2nlVB3/TAn8Ndkm/RQtGzO1qPTGCGQLtjIkD5s4RyUVGNa63Uv9z2qr2qmVO7AD2lIlHatzQMn2Er9qWej+Ns0ExKM8pF20jkiFhfBC1jDI5Cw0NxyHvUQfeQclCAdI2tT2orj+93CxDf5IaIoRw1Yegt6bZ9iw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704312394; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=5OT902UfMq+OfYqhW7dYr09e9nvZfcD1j8Js8qR42zo=; b=eCnkJ4cX2hS2H/p7YaTwCoTK/UBAChOx7d6e9lZ+cp5IEoH8Ga+EtxLjMjbNVNWCsURXXm O1NwkRU+xkGKHImcTUY4pn2JdgjjZme6sHWmN32O526KuCl87Obffyq37ZWTUSWCInzLos AGP+JTnFZ4QTmNJ6L88wHrmcB/X6bjQ= Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-228-1V_dTdFXNoyTHJgPjwGSwg-1; Wed, 03 Jan 2024 15:06:33 -0500 X-MC-Unique: 1V_dTdFXNoyTHJgPjwGSwg-1 Received: by mail-qt1-f200.google.com with SMTP id d75a77b69052e-42834c46afdso19625731cf.2 for ; Wed, 03 Jan 2024 12:06:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704312391; x=1704917191; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=5OT902UfMq+OfYqhW7dYr09e9nvZfcD1j8Js8qR42zo=; b=aCgSGPEAotVl8XtOpdfqjaefFseMWR4+WrxBADWERL1gUTfQywwbrTBbo3AnKbmtsf CI/UJhddFIcxrBdnFA3KY5evKmw4/N5cuNLU+FCv6FEIqYjvk3d5BzfGmpROJ/yLzAsH zdNRBNBlV3jtgouL98OEW6oZdOmEoD6b+1wfMJyASIpOYOLjZcz/Ma7BoDSMmMejlm7f YCErB7/+qPH6WEj5D610R8gEvOnFJkElzdUxhZbj0mnwFO7YmrGIUrHiKCQ40NRj9mat p3JjIZESEpnxmQeeVvvEz4r3n8/D0W62u0OsPu4KtoWEjdWApXEndVY3piat8e2v0bEZ M64w== X-Gm-Message-State: AOJu0Yx1xrKa8CzjtuiyaOjZmHeJk72Wo+y70lFkXcMO/8WEqxg/Feh5 E2l8RGUV14TZUHgWaE8bxIPxP5tfP8rkZJTnl2uci4nDuVlNMidLE6t21X+1oBPM+82iJQie5y3 xqh5nkmgeeJ2yxP2EFsloxqel0rRXxgTHrVGomzKXL6/koFeKHqnqDTwJLr7LzbijvFuYPCFxE0 C1O44bzxU= X-Received: by 2002:a05:622a:178d:b0:427:e769:93c9 with SMTP id s13-20020a05622a178d00b00427e76993c9mr14436005qtk.70.1704312391633; Wed, 03 Jan 2024 12:06:31 -0800 (PST) X-Google-Smtp-Source: AGHT+IHU49Tmr6LyPjLGY4nOnCDLGkuVwQUTDQ8KjRr/KAhTt7AxhkzXBm/h6BT26mSWfTKI15PMwg== X-Received: by 2002:a05:622a:178d:b0:427:e769:93c9 with SMTP id s13-20020a05622a178d00b00427e76993c9mr14435991qtk.70.1704312391179; Wed, 03 Jan 2024 12:06:31 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id cg13-20020a05622a408d00b0042831b379c7sm1821330qtb.89.2024.01.03.12.06.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 03 Jan 2024 12:06:30 -0800 (PST) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/1] c++: access of class-scope partial tmpl spec Date: Wed, 3 Jan 2024 15:06:28 -0500 Message-ID: <20240103200628.2795374-1-ppalka@redhat.com> X-Mailer: git-send-email 2.43.0.254.ga26002b628 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.2 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_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- Since partial template specializations can't be named directly, access control (when declared at class scope) doesn't apply to them, so we shouldn't have to set their TREE_PRIVATE / TREE_PROTECTED. This code was added by r10-4833-gcce3c9db9e6ffa for PR92078, but it seems better to just disable the relevant access consistency check for partial template specializations so that we also accept the below testcase. gcc/cp/ChangeLog: * parser.cc (cp_parser_check_access_in_redeclaration): Don't check access for a partial specialization. * pt.cc (maybe_new_partial_specialization): Don't set TREE_PRIVATE or TREE_PROTECTED on the newly created partial specialization. gcc/testsuite/ChangeLog: * g++.dg/template/partial-specialization14.C: New test. --- gcc/cp/parser.cc | 3 ++- gcc/cp/pt.cc | 2 -- .../g++.dg/template/partial-specialization14.C | 15 +++++++++++++++ 3 files changed, 17 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/partial-specialization14.C diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 37536faf2cf..85da15651b2 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -35062,7 +35062,8 @@ static void cp_parser_check_access_in_redeclaration (tree decl, location_t location) { if (!decl - || (!CLASS_TYPE_P (TREE_TYPE (decl)) + || (!(CLASS_TYPE_P (TREE_TYPE (decl)) + && !CLASSTYPE_TEMPLATE_SPECIALIZATION (TREE_TYPE (decl))) && TREE_CODE (TREE_TYPE (decl)) != ENUMERAL_TYPE)) return; diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 154ac76cb65..afd1df4f3d7 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -978,8 +978,6 @@ maybe_new_partial_specialization (tree& type) tree d = create_implicit_typedef (DECL_NAME (tmpl), t); DECL_CONTEXT (d) = TYPE_CONTEXT (t); DECL_SOURCE_LOCATION (d) = input_location; - TREE_PRIVATE (d) = (current_access_specifier == access_private_node); - TREE_PROTECTED (d) = (current_access_specifier == access_protected_node); TREE_PUBLIC (d) = TREE_PUBLIC (DECL_TEMPLATE_RESULT (tmpl)); set_instantiating_module (d); diff --git a/gcc/testsuite/g++.dg/template/partial-specialization14.C b/gcc/testsuite/g++.dg/template/partial-specialization14.C new file mode 100644 index 00000000000..ac7bc9ed7f1 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/partial-specialization14.C @@ -0,0 +1,15 @@ +// Verify we don't care about the access specifier when declaring +// a partial template specialization of a member class template. + +struct A1 { + template struct B { }; +private: + template struct B { }; // { dg-bogus "different access" } +}; + +struct A2 { + template struct B { }; + template struct B; +private: + template struct B { }; // { dg-bogus "different access" } +};