public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-9844] c++: constexpr if and nested generic lambda [PR99201] Date: Thu, 20 May 2021 21:34:59 +0000 (GMT) [thread overview] Message-ID: <20210520213459.7FD5B3857802@sourceware.org> (raw) https://gcc.gnu.org/g:7c365bb1462a7a9dadf9b8f8668a0c832b18056c commit r10-9844-g7c365bb1462a7a9dadf9b8f8668a0c832b18056c Author: Jason Merrill <jason@redhat.com> Date: Sun Apr 4 01:01:56 2021 -0400 c++: constexpr if and nested generic lambda [PR99201] When building up *_EXTRA_ARGS for a constexpr if or pack expansion, we need to walk into the body of a lambda to find all the local_specializations that we need to remember, like we do in find_parameter_packs_r. gcc/cp/ChangeLog: PR c++/99201 * pt.c (class el_data): Add visited field. (extract_local_specs): Pass it to cp_walk_tree. (extract_locals_r): Walk into the body of a lambda. gcc/testsuite/ChangeLog: PR c++/99201 * g++.dg/cpp1z/constexpr-if-lambda4.C: New test. Diff: --- gcc/cp/pt.c | 15 ++++++++++++++- gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda4.C | 22 ++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 8616118228c..986c8207a49 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -12672,7 +12672,11 @@ tsubst_binary_right_fold (tree t, tree args, tsubst_flags_t complain, class el_data { public: + /* Set of variables declared within the pattern. */ hash_set<tree> internal; + /* Set of AST nodes that have been visited by the traversal. */ + hash_set<tree> visited; + /* List of local_specializations used within the pattern. */ tree extra; tsubst_flags_t complain; @@ -12712,6 +12716,15 @@ extract_locals_r (tree *tp, int */*walk_subtrees*/, void *data_) } } } + else if (TREE_CODE (*tp) == LAMBDA_EXPR) + { + /* Since we defer implicit capture, look in the parms and body. */ + tree fn = lambda_function (*tp); + cp_walk_tree (&TREE_TYPE (fn), &extract_locals_r, &data, + &data.visited); + cp_walk_tree (&DECL_SAVED_TREE (fn), &extract_locals_r, &data, + &data.visited); + } else if (tree spec = retrieve_local_specialization (*tp)) { if (data.internal.contains (*tp)) @@ -12768,7 +12781,7 @@ static tree extract_local_specs (tree pattern, tsubst_flags_t complain) { el_data data (complain); - cp_walk_tree_without_duplicates (&pattern, extract_locals_r, &data); + cp_walk_tree (&pattern, extract_locals_r, &data, &data.visited); return data.extra; } diff --git a/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda4.C b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda4.C new file mode 100644 index 00000000000..99408025629 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/constexpr-if-lambda4.C @@ -0,0 +1,22 @@ +// PR c++/99201 +// { dg-do compile { target c++17 } } + +template <typename RefF> + auto + make_tester(const RefF& reffun) + { + return [=](auto in) { + auto&& expected = [&](const auto&... vs) { + if constexpr (sizeof(in) > 0) + return [&](int i) { return reffun(vs[i]...); }(0); + else + return [&](int i) { return reffun(vs[i]...); }(0); + }; + }; + } + +int main() +{ + make_tester([](int x) { return x; })(0); + return 0; +}
reply other threads:[~2021-05-20 21:34 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20210520213459.7FD5B3857802@sourceware.org \ --to=jason@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).