From patchwork Fri Dec 2 19:42:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 29091 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp1039103wrr; Fri, 2 Dec 2022 11:43:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf6abZ0Zc09SHh6yEggOAFZ+i/Yh6Hy4EJlwHdXLrCk6Dpcaih0gi3LnZIAKyUGYZMqbZMEu X-Received: by 2002:a05:6402:1f87:b0:468:7df:c38c with SMTP id c7-20020a0564021f8700b0046807dfc38cmr25813edc.150.1670010198022; Fri, 02 Dec 2022 11:43:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670010198; cv=none; d=google.com; s=arc-20160816; b=yrQxPngApfX6x5Fjqlk4SL6SePqoZXqCgNUnZTsvhrG38pIZWrU9f60V6586qk2fKr PKQojnC/v+rYqUo+1ZtWAVok9mu88InLEtkQUgAbsVMEdTB7vM3NYJGPbCaayaPgwlVm jfAmQr5jxgViSnhSgie7UkRc/FOcgIg380JR0MDLugvb9RDb8fuXr5dFaPuLjQYBZvE1 PTZMsXX10HDKxMVOk7hzsFfEIkaSdzr6DWWT2WUoWWZ0QjLgxQE7hBwtDjpZHLk0bqn7 cl1xuEnF9CW5edMVfWyctPfTvtMmNe0I8p3bWhnWhjF+GMcxd6HhOt9tl3Ztjz4n19qS U9+Q== 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:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=VNu0RgvXpbRoaCbWhtFrAtbCgEbZdPDC3+d80cZwBKs=; b=Lz3b75oKNmBFvbQo7fG21rxHbMYVcuXf1tLD3WYvEUXemV0SEJpy8FBrZruMOJwk8n Jdn8iMXflbE8FBLaEv5K7tI6N/2Jc2YE+oDPqCavua3P+0zOcn5zNlr52FaYZy1MjhOb j1/wxFuVxLgcmRRryjfVewTuyXins4BMFO3yos2z490bt5vglsKSGE6jHndmXCMARD1V OqFkQq05D1tbGq4XPbywRTuO1Nu0iyxKRuM+kSNwZzewHI/w5HWHQEjZHvSZr//IIIuW dO4vKYGhVAuaFdEqjzhfr8mPjFQMweaobWhcdCECRyAi6bUtsgj2x2u8kbc5ob571P3H ypFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U1i3OQN0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id hv9-20020a17090760c900b007ae127c6c7asi2650940ejc.176.2022.12.02.11.43.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 11:43:18 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=U1i3OQN0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 CFFBC3858417 for ; Fri, 2 Dec 2022 19:43:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFFBC3858417 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670010196; bh=VNu0RgvXpbRoaCbWhtFrAtbCgEbZdPDC3+d80cZwBKs=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=U1i3OQN0rsu2h4GDKDVIVIQ17IhfAlheUgLsnMXnPqc5KE4JbSAT8RkonKECzykGk GG2suHalycGIJ2EXoAtqQFNshoHfu62hqpWa3/UyQi+a+7fnqt4htY7m//tvyCmOC3 B4mfwwauShCw64waTbnQhQL3x8b2NWmgH2rZs46E= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id 01CE23858002 for ; Fri, 2 Dec 2022 19:42:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 01CE23858002 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-118-86Mt8VajOFCIP3-jXH8Jvw-1; Fri, 02 Dec 2022 14:42:32 -0500 X-MC-Unique: 86Mt8VajOFCIP3-jXH8Jvw-1 Received: by mail-qt1-f198.google.com with SMTP id k1-20020ac84781000000b003a6894cdd5eso20886375qtq.14 for ; Fri, 02 Dec 2022 11:42:32 -0800 (PST) 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=VNu0RgvXpbRoaCbWhtFrAtbCgEbZdPDC3+d80cZwBKs=; b=e4WJ7GGV4npwq9wLBmR8zUjvjsO04x/xPMpr4m9xow1wKw/QqwY2UhuPcJsEmFc3Gz Vq2R77qcR5Mscl1lMpDpx9fVmqecnTgoiB7HMIGBi0zL+x2TXkVlBuXx6fQsvwPfHoI9 drA0YW7RG+1R5FOwXE6Et+fMhOEfpEox252qKqjNF8V7SWqAEHPJfrgqDhmT3u50/AF4 HcwCQGOhyuniYZNl4ZseTykHFYSbZTzbs0koRrGPm3v9ip0gSbDimA5c0TGTftqDoOrG Z749cl9Rj/7dyhluZOznkB2S/MAWUblECod1aoJCiFa5EwVEH8nqR28r3A3zuddC4vqk 9iCg== X-Gm-Message-State: ANoB5pljd5d87PwjpzzVj1GBxxnPWEKBofg8a9wtETeKQBrfI4q8iYmt eCKuuN6AdlqiZl2LwTeo0u8heFybvMIFEZqawPnCle0gfPL1KMEbjqceZV5QW0El9QVSiL52utP XaTb9HPzG3Zl7C0OBdkQX01iN3L/bHES2DTFnMOZlXK8vM0e+WfhxmSOeJsX4wjAHjZI= X-Received: by 2002:ac8:5406:0:b0:3a6:8ef8:6a13 with SMTP id b6-20020ac85406000000b003a68ef86a13mr11034549qtq.563.1670010151542; Fri, 02 Dec 2022 11:42:31 -0800 (PST) X-Received: by 2002:ac8:5406:0:b0:3a6:8ef8:6a13 with SMTP id b6-20020ac85406000000b003a68ef86a13mr11034530qtq.563.1670010151202; Fri, 02 Dec 2022 11:42:31 -0800 (PST) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id l11-20020a05620a28cb00b006f9e103260dsm6535647qkp.91.2022.12.02.11.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 11:42:30 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: unexpanded pack in requires-expr parm list [PR107417] Date: Fri, 2 Dec 2022 14:42:28 -0500 Message-Id: <20221202194228.3794597-1-ppalka@redhat.com> X-Mailer: git-send-email 2.39.0.rc0.49.g083e01275b MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.7 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?1751132612885247795?= X-GMAIL-MSGID: =?utf-8?q?1751132612885247795?= Here find_parameter_packs_r isn't recognizing the unexpanded pack T inside the requires-expr's parameter list ultimately because cp_walk_trees avoids walking the parameters, for good reason: in requires (Ts... ts) { } walking 'ts' would trigger a false positive in the unexpanded pack checker since it's, well, an unexpanded pack. But we might as well walk the TREE_TYPE of each parameter still, which for_each_template_parm_r already does. Bootstrapped and regtested on x86_64-pc-linux-gne, does this look OK for trunk/12? PR c++/107417 gcc/cp/ChangeLog: * pt.cc (for_each_template_parm_r) : Move walking of the TREE_TYPE of each parameter to ... * tree.cc (cp_walk_subtrees) : ... here. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/concepts-requires33.C: New test. --- gcc/cp/pt.cc | 15 -------------- gcc/cp/tree.cc | 20 ++++++++++--------- .../g++.dg/cpp2a/concepts-requires33.C | 11 ++++++++++ 3 files changed, 22 insertions(+), 24 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-requires33.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index bc8ea06ceae..80110da2d8a 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -10573,21 +10573,6 @@ for_each_template_parm_r (tree *tp, int *walk_subtrees, void *d) return error_mark_node; break; - case REQUIRES_EXPR: - { - if (!fn) - return error_mark_node; - - /* Recursively walk the type of each constraint variable. */ - tree p = TREE_OPERAND (t, 0); - while (p) - { - WALK_SUBTREE (TREE_TYPE (p)); - p = TREE_CHAIN (p); - } - } - break; - default: break; } diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index 04a055d9d77..e9b6921df6a 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -5603,15 +5603,17 @@ cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, break; case REQUIRES_EXPR: - // Only recurse through the nested expression. Do not - // walk the parameter list. Doing so causes false - // positives in the pack expansion checker since the - // requires parameters are introduced as pack expansions. - ++cp_unevaluated_operand; - result = cp_walk_tree (&REQUIRES_EXPR_REQS (*tp), func, data, pset); - --cp_unevaluated_operand; - *walk_subtrees_p = 0; - break; + { + cp_unevaluated u; + for (tree parm = REQUIRES_EXPR_PARMS (*tp); parm; parm = DECL_CHAIN (parm)) + /* Walk the types of each parameter, but not the parameter itself. + Doing so would cause false positives in the unexpanded parameter + pack checker since a introduced parameter pack is bare. */ + WALK_SUBTREE (TREE_TYPE (parm)); + WALK_SUBTREE (REQUIRES_EXPR_REQS (*tp)); + *walk_subtrees_p = 0; + break; + } case DECL_EXPR: /* User variables should be mentioned in BIND_EXPR_VARS diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-requires33.C b/gcc/testsuite/g++.dg/cpp2a/concepts-requires33.C new file mode 100644 index 00000000000..d07ae6dee7b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires33.C @@ -0,0 +1,11 @@ +// PR c++/107417 +// { dg-do compile { target c++20 } } + +template +requires (requires (T x) { true; } && ...) +void f(); + +int main() { + f(); + f(); // { dg-error "no match" } +}