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: 14953 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp610896wru; Thu, 3 Nov 2022 08:46:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6enKZJ8aIhsu4qWpl9JINDwhMasilWSSdsWP7qKsBzluPpyZU6hFGQdiyw0LuT1wcUxWvB X-Received: by 2002:a17:907:6e90:b0:7ad:8ba7:6640 with SMTP id sh16-20020a1709076e9000b007ad8ba76640mr30603092ejc.142.1667490386807; Thu, 03 Nov 2022 08:46:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667490386; cv=none; d=google.com; s=arc-20160816; b=qfgoz5/t/FexVfCPhi++PuIpnRHepuudi2vnqW5iOTuLnI8A6lKs+ujxoP1ps+wPiB 6GuktE7OGlpI2+dme1RQzV14cQp/WbjGTl9GaXEfaxMKjX9wReAjdO8FVvxmHbJzAnJ4 rR1iSHvbJVrryqgbod4Ra69vnzmCuZzJVAxhglxa1Fb+F6yGbUCww6IujBPb27Zialpo FOI8U5MQBF+SNzXWSgjJzqqK0q7vo1HVUeu+4XGbAxcyS6rZ6DSmO194MjEyFd2RBVX1 fekTHzVAsfIFLtkZaE2l2NTEjbGCLRkS4dx0NnTTHff1g2U8sJ8PtavafweLkWPc0XuO JvNw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=2Q1wdusbt1rIFnqk9xg3HpdY8uOEXfQ6rKFRnNQ1jGg=; b=xdukd48f9G6MiTmMFBKx1Se/5zTbb2DvJOYl0l6qbxWgmF+Zmf+IO1OV7egEPz7uVz pyHcttfiHa9QamEgvPEJuTFNGSdlJNz0TPVjRt5cTK49GzXzl0wjsHSeNA8XN6rEkVL0 d0pUzdNmSkWlu3Qb9+/4dZaq871/KN6rB0KIqc536NrJdWZz6yj60h/KfXYyMqLPHoRA PYPjLiBgT78bhs0SL7f/XQF6+Vn4CnEmXbRVakK5h98hG9ekfAvTnMQQOu2EUJ3ohl+w fNFwxDzwqmTtqrPcYz/CWLLmwRyVlS/nR+RtrhR7PSjppkIa5V+SwE4n01Z0Ljajj4gC bAoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gv+CiuJM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id j15-20020a05640211cf00b0045878af0adbsi2128149edw.393.2022.11.03.08.46.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Nov 2022 08:46:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=gv+CiuJM; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0046A3858285 for ; Thu, 3 Nov 2022 15:46:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0046A3858285 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1667490384; bh=2Q1wdusbt1rIFnqk9xg3HpdY8uOEXfQ6rKFRnNQ1jGg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=gv+CiuJMItXViaTsc0Mazo5zTgGiwmwgVLYuCaI5Fdclo7Q3uszopv1oXx1EBZrcT UF6FnzDzcPqn0KfsbrsrybjEaBGm02uVJ1vl7M0KMSdKFbAUBns3K6fX13JrFZVo8Q 1rOGle/lsVZTxxYoPb8ddhW/p2i8T8FHpLshnVm0= 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-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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748490399510095134?= X-GMAIL-MSGID: =?utf-8?q?1748490399510095134?= 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 );