From patchwork Thu Nov 3 15:45:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 59843 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0F2123858420 for ; Thu, 3 Nov 2022 15:46:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0F2123858420 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667490368; bh=2Q1wdusbt1rIFnqk9xg3HpdY8uOEXfQ6rKFRnNQ1jGg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=AInmuttevlwNNvLOuMzREkhsmi2RJbm6D7wzXgcigyxRxm4yJbAcif7XyatTTnRhj GtCheFqtUt7K5tMn/9MCS1D7vOT3wfdQ9BsyfbnBb4TTSRBWSh4lh01NPOJRPddsbz onOImlT1lkji5N0AU6MEU1XHrTEAP3S3keE3LGiY= 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 ESMTPS id DBC4D3858D37 for ; Thu, 3 Nov 2022 15:45:36 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org DBC4D3858D37 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-231-v7OFEZbkO8mIM4qlmoppRg-1; Thu, 03 Nov 2022 11:45:34 -0400 X-MC-Unique: v7OFEZbkO8mIM4qlmoppRg-1 Received: by mail-qt1-f198.google.com with SMTP id i4-20020ac813c4000000b003a5044a818cso2067527qtj.11 for ; Thu, 03 Nov 2022 08:45:34 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=2Q1wdusbt1rIFnqk9xg3HpdY8uOEXfQ6rKFRnNQ1jGg=; b=OxBL3Fy4p+uan/+NmstTGti614yt7pEdB1Ze6/S01EJcH5RDkAXlJLweKoV3heS4Gy D4XFuS5D1P+Vup4ZgdMYz+xsQCuU48chIWq8QxCYhmuVxQR5Nw/lk7RQM/fD12r0c1V/ yPKiyaUkva4OljJet13q9KdcBucm3n504bPAbLB8tFR5EX4hJgFsRJzxVfuFbUncI5z4 BuiPpZXNoz7fsPnKrT20iJcccnHvwewerbWee/XN+L4LYqiCdP4PdcE3Ui3GIir1askj m3UHURzr8xVrklWqprsTw8qXcXw86MSuunTiyWyMPHwIGIM4EtFuQ8fz3TTAFe9LF+4d HBFA== X-Gm-Message-State: ACrzQf344L3AkEMBirFfKpBXrppoW9IODP28ygk7wpvHbPM/SGcYk8YT 3G+Fgjc1+7BcQH+JvBm3A8SRlVlavBarqK81hkmKP4HcIvts/Y4UlSRQAmvpAcivzvJrG9CDicy MwW2rAWGRHAxpS4zly+7FxBybQsPQe7pXlwACGLGLnyZ8+I/P3l0fEoJt7HmhSN/8dsc= X-Received: by 2002:ac8:12c1:0:b0:3a5:30ea:38c1 with SMTP id b1-20020ac812c1000000b003a530ea38c1mr14964224qtj.662.1667490333893; Thu, 03 Nov 2022 08:45:33 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5T3RaFpv9xwlyBeaq0IZdrrISHURuCEZgCSEJBTJE/8tioV3NXdbPTwi33Hdn/l9eyXX9txA== X-Received: by 2002:ac8:12c1:0:b0:3a5:30ea:38c1 with SMTP id b1-20020ac812c1000000b003a530ea38c1mr14964192qtj.662.1667490333557; Thu, 03 Nov 2022 08:45:33 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id c2-20020a05620a134200b006ecf030ef15sm943346qkl.65.2022.11.03.08.45.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 08:45:32 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: requires-expr substitution and access checking [PR107179] Date: Thu, 3 Nov 2022 11:45:30 -0400 Message-Id: <20221103154530.1442773-1-ppalka@redhat.com> X-Mailer: git-send-email 2.38.1.381.gc03801e19c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 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 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.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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Like during satisfaction, we need to check access immediately during substitution of a requires-expr since the outcome of an access check can determine the value of the requires-expr. And otherwise, in contexts where access checking is deferred (such as during substitution into a base-clause), a failed access check may leak out from the requires-expr into a non-SFINAE context and cause a hard error (as in the testcase below). Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/107179 gcc/cp/ChangeLog: * constraint.cc (tsubst_requires_expr): Make sure we're not deferring access checks. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires31.C: New test. --- gcc/cp/constraint.cc | 3 +++ gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C | 13 +++++++++++++ 2 files changed, 16 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 5e6a3bcf059..f6ef078171a 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2252,6 +2252,9 @@ tsubst_requires_expr (tree t, tree args, sat_info info) { local_specialization_stack stack (lss_copy); + /* We need to check access during the substitution. */ + deferring_access_check_sentinel acs (dk_no_deferred); + /* A requires-expression is an unevaluated context. */ cp_unevaluated u; diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C new file mode 100644 index 00000000000..9b7e2a34889 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires31.C @@ -0,0 +1,13 @@ +// PR c++/107179 +// { dg-do compile { target c++20 } } + +template struct bool_constant { static constexpr bool value = B; }; + +template + struct is_implicitly_default_constructible + : bool_constant + { }; + +struct X { private: X(); }; + +static_assert( !is_implicitly_default_constructible::value );