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: 1711569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Jw/9Xf/h; dkim-atps=neutral Received: from sourceware.org (ip-8-43-85-97.sourceware.org [8.43.85.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4NP3JK6nH6z23nC for ; Sat, 3 Dec 2022 06:42:56 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9E6333858407 for ; Fri, 2 Dec 2022 19:42:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9E6333858407 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1670010173; 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=Jw/9Xf/hewaOOkdj/vKAn+Bv+e94z/htSPyY20rakZoKqdADJZhGmQB7tYq4qpmN8 g/kbd/ADysRV6nJoxKLBwIfEabikQG6RfK0btT4H1heVT/x2x68IAHVlkFSYtQOdbq Qm1BMqkGUZ3SfzCz4OuPwsmrBt6ONy9gpuzvNf2U= 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-Google-Smtp-Source: AA0mqf7XDpuLM5+1EimduTdcg/KbqyjJ7CUze66tvtau/Spt/SkTpiQjFVlSEvJp8SqPrmowWYkISw== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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" } +}