[clang] [clang-format] Fix crash in TokenAnnotator (PR #82349)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 20 22:16:36 PST 2024


================
@@ -3817,7 +3817,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
         do {
           Tok = Tok->Next;
         } while (Tok && Tok->isNot(TT_OverloadedOperatorLParen));
-        if (!Tok)
+        if (!Tok || !Tok->Next)
----------------
owenca wrote:

```suggestion
        if (!Tok || !Tok->MatchingParen)
```
Otherwise, it would still crash if the unmatched `l_paren` is not the last token on the line, e.g.:
```
struct Foo {
  operator foo(bar
};

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


More information about the cfe-commits mailing list