From patchwork Tue Jun 29 17:57:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1498511 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=rGiXDrCs; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GDsfp2LkWz9sWD for ; Wed, 30 Jun 2021 03:58:56 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D44B93854804 for ; Tue, 29 Jun 2021 17:58:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D44B93854804 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1624989532; bh=j7H41zJpXNatCj5nTK+MBQ1MZmOOQGCPfroF9+tyaYk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=rGiXDrCsyIjWbjnVeF3EMQRWXHo6VfxQsdFBWYOeOuCWYY4+a+iTz6bUdpvVs6R97 hoIc8OoJ9RrXG4xPLBbtXcCTw+MneZYEGFIb4mx97fUxq0a18e45N/lxxPl6bIUM2+ fNMSQoOeEmt0ShhdcCjEOK30oNjtNk0N9NVXofvA= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 16BA63857C7F for ; Tue, 29 Jun 2021 17:58:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16BA63857C7F Received: from mail-qt1-f200.google.com (mail-qt1-f200.google.com [209.85.160.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-51-FkPzmjmVP7KfUW034622DQ-1; Tue, 29 Jun 2021 13:58:07 -0400 X-MC-Unique: FkPzmjmVP7KfUW034622DQ-1 Received: by mail-qt1-f200.google.com with SMTP id t15-20020a05622a180fb029024f88c5e9b0so8883880qtc.17 for ; Tue, 29 Jun 2021 10:58:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=j7H41zJpXNatCj5nTK+MBQ1MZmOOQGCPfroF9+tyaYk=; b=I912N4c+Nke0ueHVtgBeYt0LogvpxbAXBRnB2bDKeXSDBJoLrRQZjFx0ngdyWfdcly 6y7Oud6J1/ywW9xnpnPmT4BQaiSXiQuwA4C1fIueea7WRXWLtvTqV8Fx3rkF322kjz3q RbwJgRkC8hvC8TuB4aFXRa4YjhemUCqjns8ALSMD1Q5uwPUY9Na3uQXCwGOyn8rZ9psK z8NxLz5QUzltY8uckr1JlSzuL5wDDRU+kpcnRE4UewtGwz0QcEciZR/TZFGXNWw8/c+C +fD3MQhVMSY4gVPP67dpTXrgFKjQrh6Am8lcJTs6Zg0UZKDdm3deyeoh4GUOsRi+tnpf fZLA== X-Gm-Message-State: AOAM5339rEw+n2xERVoMAEo6zaU0/ppZhAt0vjTAjpVQQpE5paLpNIOq sJygcnRdfZcd/RD6nVSSVuBywqljw69DsRkaKTtDgRTRSV1Avi+uxhurvID3XE9FnboHAj55qf9 /LDjrUTPDiUMisLkBcbSFRLDuCqqw0V2SL934f2VRTwf2w/XcTpe+Vyi/3xZm9H21+5Q= X-Received: by 2002:a37:a390:: with SMTP id m138mr28795141qke.284.1624989486683; Tue, 29 Jun 2021 10:58:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyttc7fwda/Jd82dIPxjsSzksOVzK7QT7mBjDBcw5kBhqDY2IovCNDb1JN+ZUsYOIkOQF7Zqw== X-Received: by 2002:a37:a390:: with SMTP id m138mr28795111qke.284.1624989486429; Tue, 29 Jun 2021 10:58:06 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id b8sm9745502qtr.77.2021.06.29.10.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Jun 2021 10:58:06 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH 2/2] c++: Extend PR96204 fix to variable templates Date: Tue, 29 Jun 2021 13:57:23 -0400 Message-Id: <20210629175723.1009233-2-ppalka@redhat.com> X-Mailer: git-send-email 2.32.0.93.g670b81a890 In-Reply-To: <20210629175723.1009233-1-ppalka@redhat.com> References: <20210629175723.1009233-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.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_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Patrick Palka via Gcc-patches From: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" r12-1829 corrected the access scope during partial specialization matching of class templates, but neglected the variable template case. This patch moves the access scope adjustment to inside most_specialized_partial_spec, so that all callers can benefit. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/96204 gcc/cp/ChangeLog: * pt.c (instantiate_class_template_1): Remove call to push_nested_class and pop_nested_class added by r12-1829. (most_specialized_partial_spec): Use push_access_scope_guard and deferring_access_check_sentinel. gcc/testsuite/ChangeLog: * g++.dg/template/access40b.C: New test. --- gcc/cp/pt.c | 12 +++++++---- gcc/testsuite/g++.dg/template/access40b.C | 26 +++++++++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 gcc/testsuite/g++.dg/template/access40b.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index bd8b17ca047..1e2e2ba5329 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -11776,11 +11776,8 @@ instantiate_class_template_1 (tree type) deferring_access_check_sentinel acs (dk_no_deferred); /* Determine what specialization of the original template to - instantiate; do this relative to the scope of the class for - sake of access checking. */ - push_nested_class (type); + instantiate. */ t = most_specialized_partial_spec (type, tf_warning_or_error); - pop_nested_class (); if (t == error_mark_node) return error_mark_node; else if (t) @@ -24989,26 +24986,33 @@ most_specialized_partial_spec (tree target, tsubst_flags_t complain) tree outer_args = NULL_TREE; tree tmpl, args; + tree decl; if (TYPE_P (target)) { tree tinfo = CLASSTYPE_TEMPLATE_INFO (target); tmpl = TI_TEMPLATE (tinfo); args = TI_ARGS (tinfo); + decl = TYPE_NAME (target); } else if (TREE_CODE (target) == TEMPLATE_ID_EXPR) { tmpl = TREE_OPERAND (target, 0); args = TREE_OPERAND (target, 1); + decl = DECL_TEMPLATE_RESULT (tmpl); } else if (VAR_P (target)) { tree tinfo = DECL_TEMPLATE_INFO (target); tmpl = TI_TEMPLATE (tinfo); args = TI_ARGS (tinfo); + decl = target; } else gcc_unreachable (); + push_access_scope_guard pas (decl); + deferring_access_check_sentinel acs (dk_no_deferred); + tree main_tmpl = most_general_template (tmpl); /* For determining which partial specialization to use, only the diff --git a/gcc/testsuite/g++.dg/template/access40b.C b/gcc/testsuite/g++.dg/template/access40b.C new file mode 100644 index 00000000000..040e3d18096 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/access40b.C @@ -0,0 +1,26 @@ +// PR c++/96204 +// { dg-do compile { target c++14 } } +// A variant of access40.C where has_type_member is a variable template instead +// of a class template. + +template +constexpr bool has_type_member = false; + +template +constexpr bool has_type_member = true; + +struct Parent; + +struct Child { +private: + friend struct Parent; + typedef void type; +}; + +struct Parent { + static void f() { + // The partial specialization does not match despite Child::type + // being accessible from the current scope. + static_assert(!has_type_member, ""); + } +};