]> gcc.gnu.org Git - gcc.git/commitdiff
c++: lambda template in requires [PR105541]
authorJason Merrill <jason@redhat.com>
Wed, 11 May 2022 18:53:26 +0000 (14:53 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 11 May 2022 19:30:17 +0000 (15:30 -0400)
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.

gcc/cp/cp-tree.h
gcc/cp/parser.cc
gcc/testsuite/g++.dg/cpp2a/lambda-requires1.C [new file with mode: 0644]

index e16b8d708463fa7734400e77c264bb3dce4a1b1e..b6961a796af84c8cfa75d6da9e097b342bdd63c9 100644 (file)
@@ -3771,11 +3771,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.  */
index 4ed9feaa427808cfed5563f83d219712b57f47b1..d09d5b7c8b7434d16dc98c486f94b5e148617a90 100644 (file)
@@ -32151,7 +32151,10 @@ cp_parser_enclosed_template_argument_list (cp_parser* parser)
       || cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT)
       || cp_lexer_next_token_is (parser->lexer, CPP_GREATER_EQ)
       || cp_lexer_next_token_is (parser->lexer, CPP_RSHIFT_EQ))
-    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 (file)
index 0000000..fdfdaeb
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/105541
+// { dg-do compile { target c++20 } }
+
+static_assert(requires { []<typename T>{}; });
This page took 0.12313 seconds and 5 git commands to generate.