From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 D684C3858D39 for ; Mon, 1 May 2023 19:59:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D684C3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1682971151; 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: in-reply-to:in-reply-to:references:references; bh=6BQ3RoMl6HNVZjA43DT1hoF8keG6MPkN0SFAitrXUXc=; b=FnXCFMOYNXuRhNFtRCSng4DjjZqosE7gvKL6jpDXg4SYxnaLSCQ9zwtz8zMTNxwxctadek wKEZbu9PRBO+vwU8wUW4CyGbCOIL0BxulMiWkCPRPPdgVSZOUZR+YrqPZlIyTuAZu2y0iw pVP0JTo25El41Imr5ZwmNZBj3JK9+Wc= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-618-12YP_ElQNEaOZYMDiWC2Ug-1; Mon, 01 May 2023 15:59:08 -0400 X-MC-Unique: 12YP_ElQNEaOZYMDiWC2Ug-1 Received: by mail-qt1-f197.google.com with SMTP id d75a77b69052e-3ece8a3e6e8so16386221cf.0 for ; Mon, 01 May 2023 12:59:08 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682971147; x=1685563147; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=6BQ3RoMl6HNVZjA43DT1hoF8keG6MPkN0SFAitrXUXc=; b=KzIe7WNpMrmyQYzUI4tMuZFN85iDdSGvOONH5TJp7e1UlXSBK4LD6uknqZ2fckzNXg b+nyZthdAbncH5h/nAepoWJbBMbj1ZRcgyvLI65ZGX/k0dXtINOAw9hatuAF28QdL6+9 L3yra/VlWSkOJFfUCAy9qCMCUFUbN7RqWQK7pGX+mMoUPDilPHrwXg3IK4M2Hl+aW/pa P9Z5OhrnYYuV57S3lmZIoRNRHUQ8PpFiCRSzzbUMld7w8fKcPGjKySJS2EqlL9cfZDKb 0W0yMpf/aQ8EiOPWOuWMDLRxqywdkSRJyl6hykX4sryXD+gTvJPMeWaZrUZdbGCHhAk/ vZaQ== X-Gm-Message-State: AC+VfDxddN5kpl4D0AUkaMZWT7m/w/TKBKeb4thlLHkH/4YRu8NcmKwf Z007502PqfRRAtlVw5rvIKAdezW/4eNDh0iOPzPa89LY5Yc7ZWXQ66tFWOmbdQBxfHI4kmtTZVp PrlOlF2KtZMeg81aI0qf0b/WTKOo6P6FCuRmXOPPE4X05zqnvysBa2IR7jHsi1ikIAY+mQO3Ff/ 4= X-Received: by 2002:ac8:5e0d:0:b0:3ef:3bad:6d05 with SMTP id h13-20020ac85e0d000000b003ef3bad6d05mr22504389qtx.2.1682971147322; Mon, 01 May 2023 12:59:07 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7cboPDVSIQbf9Qzg0KaUe+edw+yOUjn1a7w0QzZFIqKBfP6Nur4EhNOD6XH0GVQjm65Sy1OQ== X-Received: by 2002:ac8:5e0d:0:b0:3ef:3bad:6d05 with SMTP id h13-20020ac85e0d000000b003ef3bad6d05mr22504370qtx.2.1682971147015; Mon, 01 May 2023 12:59:07 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id 9-20020ac85909000000b003ef573e24cfsm9303705qty.12.2023.05.01.12.59.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 01 May 2023 12:59:06 -0700 (PDT) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH 2/2] c++: non-dep init folding and access checking [PR109480] Date: Mon, 1 May 2023 15:59:02 -0400 Message-ID: <20230501195902.1915703-2-ppalka@redhat.com> X-Mailer: git-send-email 2.40.1.459.g48d89b51b3 In-Reply-To: <20230501195902.1915703-1-ppalka@redhat.com> References: <20230501195902.1915703-1-ppalka@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-13.8 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_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 List-Id: enforce_access currently inspects processing_template_decl to determine whether to defer the given access check until instantiation time. But using this flag is unreliable because it gets cleared during e.g. non-dependent initializer folding, and can lead to premature access check failures as in the below testcase. It seems better to inspect current_template_parms instead. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/109480 gcc/cp/ChangeLog: * semantics.cc (enforce_access): Check current_template_parms instead of processing_template_decl when determining whether to defer the access check. gcc/testsuite/ChangeLog: * g++.dg/template/non-dependent25a.C: New test. --- gcc/cp/semantics.cc | 2 +- .../g++.dg/template/non-dependent25a.C | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/template/non-dependent25a.C diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc index 9ba316ab3be..474da71bff6 100644 --- a/gcc/cp/semantics.cc +++ b/gcc/cp/semantics.cc @@ -346,7 +346,7 @@ enforce_access (tree basetype_path, tree decl, tree diag_decl, } tree cs = current_scope (); - if (processing_template_decl + if (current_template_parms && (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL)) if (tree template_info = get_template_info (cs)) { diff --git a/gcc/testsuite/g++.dg/template/non-dependent25a.C b/gcc/testsuite/g++.dg/template/non-dependent25a.C new file mode 100644 index 00000000000..902e537ec09 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent25a.C @@ -0,0 +1,17 @@ +// PR c++/109480 +// A version of non-dependent25.C where b's initializer is a constant +// expression. +// { dg-do compile { target c++11 } } + +template +struct A { + void f() { + constexpr A a; + const bool b = a.g(); // { dg-bogus "private" } + } + +private: + constexpr bool g() const { return true; } +}; + +template struct A; -- 2.40.1.459.g48d89b51b3