[clang] [clang]fix ppcaching assertion gh186582 (PR #187370)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 18 13:00:56 PDT 2026
https://github.com/Serosh-commits created https://github.com/llvm/llvm-project/pull/187370
Revert tentative action if 'operator' does not form a valid template-id. This ensures cached tokens match the scope range. fixes #186582.
>From 14866a5568d927922ba211b13e0303cb6df330d9 Mon Sep 17 00:00:00 2001
From: Serosh-commits <janmejayapanda400 at gmail.com>
Date: Thu, 19 Mar 2026 00:57:24 +0530
Subject: [PATCH] [Clang] Fix assertion failure in PPCaching.cpp for
'::template operator'
Revert tentative action if 'operator' does not form a valid template-id.
This ensures cached tokens match the scope range. Fixes GH#186582.
---
clang/docs/ReleaseNotes.rst | 1 +
clang/lib/Parse/ParseExprCXX.cpp | 4 ++--
clang/test/Parser/gh186582.cpp | 13 +++++++++++++
3 files changed, 16 insertions(+), 2 deletions(-)
create mode 100644 clang/test/Parser/gh186582.cpp
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 613d87668be18..0f72c8e341e4c 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -227,6 +227,7 @@ Bug Fixes in This Version
- Fixed atomic boolean compound assignment; the conversion back to atomic bool would be miscompiled. (#GH33210)
- Fixed a failed assertion in the preprocessor when ``__has_embed`` parameters are missing parentheses. (#GH175088)
+- Fixed an assertion failure in the preprocessor when encountering ``::template operator`` during tentative parsing. (#GH186582)
- Fix lifetime extension of temporaries in for-range-initializers in templates. (#GH165182)
- Fixed a preprocessor crash in ``__has_cpp_attribute`` on incomplete scoped attributes. (#GH178098)
diff --git a/clang/lib/Parse/ParseExprCXX.cpp b/clang/lib/Parse/ParseExprCXX.cpp
index 842b52375eb14..b50b5c383b961 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -286,7 +286,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
// we already annotated the template-id.
if (ParseUnqualifiedIdOperator(SS, EnteringContext, ObjectType,
TemplateName)) {
- TPA.Commit();
+ TPA.Revert();
break;
}
@@ -295,7 +295,7 @@ bool Parser::ParseOptionalCXXScopeSpecifier(
Diag(TemplateName.getSourceRange().getBegin(),
diag::err_id_after_template_in_nested_name_spec)
<< TemplateName.getSourceRange();
- TPA.Commit();
+ TPA.Revert();
break;
}
} else {
diff --git a/clang/test/Parser/gh186582.cpp b/clang/test/Parser/gh186582.cpp
new file mode 100644
index 0000000000000..c3305813dd445
--- /dev/null
+++ b/clang/test/Parser/gh186582.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void f() {
+ a( ::template operator
+} // expected-error {{expected a type}} \
+ // expected-error {{expected unqualified-id}} \
+ // expected-error {{use of undeclared identifier 'a'}} \
+ // expected-error {{expected ')'}} \
+ // expected-note {{to match this '('}} \
+ // expected-error {{expected ';' after expression}}
+
+// expected-error {{expected '}'}} \
+// expected-note {{to match this '{'}}
More information about the cfe-commits
mailing list