[clang] 83164a4 - [Clang] fix assertion failure in ::template operator parsing (#194097)

via cfe-commits cfe-commits at lists.llvm.org
Tue Apr 28 06:13:32 PDT 2026


Author: Serosh
Date: 2026-04-28T06:13:26-07:00
New Revision: 83164a43a1eef61f1e0f6078718a68adb21489ee

URL: https://github.com/llvm/llvm-project/commit/83164a43a1eef61f1e0f6078718a68adb21489ee
DIFF: https://github.com/llvm/llvm-project/commit/83164a43a1eef61f1e0f6078718a68adb21489ee.diff

LOG: [Clang] fix assertion failure in ::template operator parsing (#194097)

when parsing an invalid `::template operator`, the parser incorrectly
kept the consumed tokens on error. This caused the token cache to go out
of sync and crash. This patch fixes it by reverting the tokens and
properly returning the error
fixes #186582

Added: 
    clang/test/Parser/gh186582.cpp

Modified: 
    clang/docs/ReleaseNotes.rst
    clang/lib/Parse/ParseExprCXX.cpp

Removed: 
    


################################################################################
diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index ec64c2008d89b..0a13bf6b3ce14 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -532,6 +532,7 @@ Bug Fixes to Attribute Support
 
 Bug Fixes to C++ Support
 ^^^^^^^^^^^^^^^^^^^^^^^^
+- Fixed a preprocessor assertion failure triggered when parsing an invalid template-id starting with ``::template operator``. (#GH186582)
 - Fixed a crash when a function template is defined as a non-template friend with a global scope qualifier. (#GH185341)
 - Clang now rejects constant template parameters with block pointer types, since these are not implemented anyway and would lead to crashes. (#GH189247)
 - Fixed a crash on error recovery when dealing with invalid templates. (#GH183075)

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 8903b638d49a4..39c61f4b5bf5c 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -287,8 +287,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
         // we already annotated the template-id.
         if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
                                        TemplateName)) {
-          TPA.Commit();
-          break;
+          TPA.Revert();
+          return true;
         }
 
         if (TemplateName.getKind() != UnqualifiedIdKind::IK_OperatorFunctionId &&
@@ -296,8 +296,8 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
           Diag(TemplateName.getSourceRange().getBegin(),
                diag::err_id_after_template_in_nested_name_spec)
             << TemplateName.getSourceRange();
-          TPA.Commit();
-          break;
+          TPA.Revert();
+          return true;
         }
       } else {
         TPA.Revert();

diff  --git a/clang/test/Parser/gh186582.cpp b/clang/test/Parser/gh186582.cpp
new file mode 100644
index 0000000000000..d5b1102586833
--- /dev/null
+++ b/clang/test/Parser/gh186582.cpp
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+a(   ::template operator
+// expected-error at -1 {{unknown type name 'a'}}
+// expected-error at -2 {{expected unqualified-id}}
+// expected-error at -3 {{expected ')'}}
+// expected-note at -4 {{to match this '('}}
+// expected-error@* 2{{expected a type}}


        


More information about the cfe-commits mailing list