]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: parse error with >= in template argument list [PR105436]
authorMarek Polacek <polacek@redhat.com>
Fri, 29 Apr 2022 21:03:41 +0000 (17:03 -0400)
committerMarek Polacek <polacek@redhat.com>
Wed, 4 May 2022 16:01:31 +0000 (12:01 -0400)
This patch fixes an oversight whereby we treated >= as the end of
a template argument.  This causes problems in C++14, because in
cp_parser_template_argument we go different ways for C++14 and C++17:

  /* It must be a non-type argument.  In C++17 any constant-expression is
     allowed.  */
  if (cxx_dialect > cxx14)
    goto general_expr;

so in this testcase in C++14 we get "N" as the template argument but in
C++17 it is the whole "N >= 5" expression.  So in C++14 the remaining
">= 5" triggered the newly-added diagnostic.

PR c++/105436

gcc/cp/ChangeLog:

* parser.cc (cp_parser_next_token_ends_template_argument_p): Don't
return true for CPP_GREATER_EQ.

gcc/testsuite/ChangeLog:

* g++.dg/parse/template31.C: New test.

gcc/cp/parser.cc
gcc/testsuite/g++.dg/parse/template31.C [new file with mode: 0644]

index a5cbb3e896fc210d39d99be9f5c039f9cc1cd3dc..5fa743b5a8edbe877938fe61708187e565e574d6 100644 (file)
@@ -33224,7 +33224,6 @@ cp_parser_next_token_ends_template_argument_p (cp_parser *parser)
          || ((cxx_dialect != cxx98) && token->type == CPP_RSHIFT)
          /* For better diagnostics, treat >>= like that too, that
             shouldn't appear non-nested in template arguments.  */
-         || token->type == CPP_GREATER_EQ
          || token->type == CPP_RSHIFT_EQ);
 }
 
diff --git a/gcc/testsuite/g++.dg/parse/template31.C b/gcc/testsuite/g++.dg/parse/template31.C
new file mode 100644 (file)
index 0000000..a5693e8
--- /dev/null
@@ -0,0 +1,4 @@
+// PR c++/105436
+
+template<bool> struct A;
+template<int N> A<N >= 5> f();