]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: -Wtemplate-body and tentative parsing [PR120575]
authorJason Merrill <jason@redhat.com>
Fri, 4 Jul 2025 09:15:00 +0000 (05:15 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 4 Jul 2025 13:48:01 +0000 (09:48 -0400)
Here we were asserting non-zero errorcount, which is not the case if the
parse error was reduced to a warning (or silenced) in a template body.  So
check seen_error instead.

PR c++/120575
PR c++/116064

gcc/cp/ChangeLog:

* parser.cc (cp_parser_abort_tentative_parse): Check seen_error
instead of errorcount.

gcc/testsuite/ChangeLog:

* g++.dg/template/permissive-error3.C: New test.

gcc/cp/parser.cc
gcc/testsuite/g++.dg/template/permissive-error3.C [new file with mode: 0644]

index 617b7cd47d8fc277a31689363256c0ba892732f2..cac74e36ece92765b64fd16395ad4dd5b6afccc4 100644 (file)
@@ -36664,7 +36664,7 @@ static void
 cp_parser_abort_tentative_parse (cp_parser* parser)
 {
   gcc_assert (parser->context->status != CP_PARSER_STATUS_KIND_COMMITTED
-             || errorcount > 0);
+             || seen_error ());
   cp_parser_simulate_error (parser);
   /* Now, pretend that we want to see if the construct was
      successfully parsed.  */
diff --git a/gcc/testsuite/g++.dg/template/permissive-error3.C b/gcc/testsuite/g++.dg/template/permissive-error3.C
new file mode 100644 (file)
index 0000000..988b7fa
--- /dev/null
@@ -0,0 +1,12 @@
+// PR c++/120575
+// { dg-additional-options -Wno-template-body }
+
+template< int >
+struct T {};
+
+template< int >
+struct S {
+
+  operator typename T< oops >::anything () {};
+
+};