From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1888) id 27D8D3858C33; Mon, 19 Dec 2022 16:54:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 27D8D3858C33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1671468880; bh=PuLCVfcQW7P2nKGUnRYpbUQVP7e/3uZ27v5LGchkE8A=; h=From:To:Subject:Date:From; b=EIBW3AK7K2WKu3OyPFPKAUz7qQ64H90wm/W4e5ZSzoiOg1iAIakCCKfkHBctuI9jk 1aJ2dzJXkS3tgkD99IGDx9m1rpz/5DTd3t/9TFtwav6BL69c38RiEnDX+xrUmfl5Z3 Z8njlwhdDWIYMxhgHS3e5jtMDrj53gD8Hcwg1hic= MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Patrick Palka To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-8996] c++: pack in requires-expr parm list [PR107417] X-Act-Checkin: gcc X-Git-Author: Patrick Palka X-Git-Refname: refs/heads/releases/gcc-12 X-Git-Oldrev: 648db321893acabd06c24da149c09fceab4daeff X-Git-Newrev: b428bb449be1bdbbd4000b51bb7c665981dc8c8f Message-Id: <20221219165440.27D8D3858C33@sourceware.org> Date: Mon, 19 Dec 2022 16:54:40 +0000 (GMT) List-Id: https://gcc.gnu.org/g:b428bb449be1bdbbd4000b51bb7c665981dc8c8f commit r12-8996-gb428bb449be1bdbbd4000b51bb7c665981dc8c8f Author: Patrick Palka Date: Sun Dec 4 10:47:24 2022 -0500 c++: pack in requires-expr parm list [PR107417] Here find_parameter_packs_r isn't detecting the pack T inside the requires-expr's parameter list ultimately because cp_walk_trees deliberately avoids walking the list so as to avoid false positives in the unexpanded pack checker. But it should still be fine to walk the TREE_TYPE of each parameter, which we already need to do from for_each_template_parm_r, and is sufficient to fix the testcase. 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. (cherry picked from commit 079add3ad39d6620d34665dd9c26c21951eb657c) Diff: --- gcc/cp/pt.cc | 15 --------------- gcc/cp/tree.cc | 21 ++++++++++++--------- gcc/testsuite/g++.dg/cpp2a/concepts-requires33.C | 10 ++++++++++ 3 files changed, 22 insertions(+), 24 deletions(-) diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index cb674cc2258..a5f14ef98e8 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -10648,21 +10648,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 3b37567cbd7..bc521f8ae9c 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -5488,15 +5488,18 @@ 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, + since doing so would cause false positives in the unexpanded pack + checker if the requires-expr introduces a function parameter pack, + e.g. requires (Ts... ts) { }. */ + 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..1ff237ac382 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-requires33.C @@ -0,0 +1,10 @@ +// PR c++/107417 +// { dg-do compile { target c++20 } } + +template +void f() requires (requires (T x) { true; } && ...); + +int main() { + f(); + f(); // { dg-error "no match" } +}