[clang] Fix crash in AnnotateExistingDecltypeSpecifier for invalid decltype syntax Issue #165246 (PR #167114)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 20 06:12:56 PST 2025


================
@@ -1132,6 +1132,12 @@ void Parser::AnnotateExistingDecltypeSpecifier(const DeclSpec &DS,
   // make sure we have a token we can turn into an annotation token
   if (PP.isBacktrackEnabled()) {
     PP.RevertCachedTokens(1);
+    if (DS.getTypeSpecType() == TST_error) {
+      // make sure we have meaningful cached tokens
+      if (EndLoc.isValid() && StartLoc.isValid() && EndLoc != StartLoc) {
----------------
erichkeane wrote:

Not really a bit of code I play with, the != and `EndLoc` conditions here seem odd to me.  Why do we care that the `EndLoc`, which we are going to assign, is valid?  And why would them being different matter for the caching? 

https://github.com/llvm/llvm-project/pull/167114


More information about the cfe-commits mailing list