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.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 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=1667490336; 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=2Q1wdusbt1rIFnqk9xg3HpdY8uOEXfQ6rKFRnNQ1jGg=; b=Z+oNb3wWHW3FFbNMH3JSModcgKxDDStY2OGtWRUZ6DJCidqEo3yim9PBZvsAodCaM19Aym a1kzVtO/ishRZJxAzZtPx6Ee7rnp/oblQc9zaGGpreF8/Iap66pqLULzOeY3f91/Q41ZCV xSN1V5+DRA3++UyaEITGrNXws3qNmAY= 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) From: Patrick Palka To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka 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 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 List-Id: 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 ); -- 2.38.1.381.gc03801e19c