diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2851,6 +2851,8 @@ return false; } else if (isCppAttribute(IsCpp, *Next)) { Next = Next->MatchingParen; + if (!Next) + return false; } else if (Next->is(tok::l_paren)) { break; } else { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -25017,6 +25017,8 @@ "}", Style); + verifyIncompleteFormat("class C final [[deprecated(l]] {});", Style); + // These tests are here to show a problem that may not be easily // solved, our implementation to remove semicolons is only as good // as our FunctionLBrace detection and this fails for empty braces