https://gcc.gnu.org/g:799dfe7c5f638a645d33b47750f797b3fb87329b

commit r15-9927-g799dfe7c5f638a645d33b47750f797b3fb87329b
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Jul 4 05:15:00 2025 -0400

    c++: -Wtemplate-body and tentative parsing [PR120575]
    
    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.
    
    (cherry picked from commit 35d6f55f7d6655a8683b45286283d44674fa997e)

Diff:
---
 gcc/cp/parser.cc                                  |  2 +-
 gcc/testsuite/g++.dg/template/permissive-error3.C | 12 ++++++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index fe1eee94897b..b3d88d44f1b6 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -36601,7 +36601,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
index 000000000000..988b7fa39deb
--- /dev/null
+++ b/gcc/testsuite/g++.dg/template/permissive-error3.C
@@ -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 () {};
+
+};

Reply via email to