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 r12-8535] c++: lambda template in requires [PR105541] Date: Fri, 1 Jul 2022 14:56:10 +0000 (GMT) [thread overview] Message-ID: <20220701145610.39076385F01B@sourceware.org> (raw) https://gcc.gnu.org/g:b1c8ee2627696717013ebdb1ca3f5f97a76b1cb9 commit r12-8535-gb1c8ee2627696717013ebdb1ca3f5f97a76b1cb9 Author: Jason Merrill <jason@redhat.com> Date: Wed May 11 14:53:26 2022 -0400 c++: lambda template in requires [PR105541] Since the patch for PR103408, the template parameters for the lambda in this test have level 1 instead of 2, and we were treating null template args as 1 level of arguments, so tsubst_template_parms decided it had nothing to do. Fixed by distinguishing between <> and no args at all, which is what we have in our "substitution" in a requires-expression. PR c++/105541 gcc/cp/ChangeLog: * cp-tree.h (TMPL_ARGS_DEPTH): 0 for null args. * parser.cc (cp_parser_enclosed_template_argument_list): Use 0-length TREE_VEC for <>. gcc/testsuite/ChangeLog: * g++.dg/cpp2a/lambda-requires1.C: New test. Diff: --- gcc/cp/cp-tree.h | 12 +++++++----- gcc/cp/parser.cc | 5 ++++- gcc/testsuite/g++.dg/cpp2a/lambda-requires1.C | 4 ++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 97610e319bb..2db847868b6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -3779,11 +3779,13 @@ struct GTY(()) lang_decl { /* The depth of a template argument vector. When called directly by the parser, we use a TREE_LIST rather than a TREE_VEC to represent - template arguments. In fact, we may even see NULL_TREE if there - are no template arguments. In both of those cases, there is only - one level of template arguments. */ -#define TMPL_ARGS_DEPTH(NODE) \ - (TMPL_ARGS_HAVE_MULTIPLE_LEVELS (NODE) ? TREE_VEC_LENGTH (NODE) : 1) + template arguments. In that case, there is only one level of template + arguments. We may even see NULL_TREE if there are 0 levels of + template arguments, as in cp_parser_requires_expression. */ +#define TMPL_ARGS_DEPTH(NODE) \ + ((NODE) == NULL_TREE ? 0 \ + : TMPL_ARGS_HAVE_MULTIPLE_LEVELS (NODE) ? TREE_VEC_LENGTH (NODE) \ + : 1) /* The LEVELth level of the template ARGS. The outermost level of args is level 1, not level 0. */ diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc index 1ec345e3811..ad717f73e3b 100644 --- a/gcc/cp/parser.cc +++ b/gcc/cp/parser.cc @@ -32067,7 +32067,10 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser) /* Parse the template-argument-list itself. */ if (cp_lexer_next_token_is (parser->lexer, CPP_GREATER) || cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT)) - arguments = NULL_TREE; + { + arguments = make_tree_vec (0); + SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (arguments, 0); + } else arguments = cp_parser_template_argument_list (parser); /* Look for the `>' that ends the template-argument-list. If we find diff --git a/gcc/testsuite/g++.dg/cpp2a/lambda-requires1.C b/gcc/testsuite/g++.dg/cpp2a/lambda-requires1.C new file mode 100644 index 00000000000..fdfdaebcf6a --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/lambda-requires1.C @@ -0,0 +1,4 @@ +// PR c++/105541 +// { dg-do compile { target c++20 } } + +static_assert(requires { []<typename T>{}; });
reply other threads:[~2022-07-01 14:56 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=20220701145610.39076385F01B@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).