diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 21152b8c20e11..7f16d04d898b9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2851,6 +2851,8 @@ static bool isFunctionDeclarationName(bool IsCpp, const FormatToken &Current, 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 index d4150f46d1f58..1db8ee94369b7 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -25017,6 +25017,8 @@ TEST_F(FormatTest, RemoveSemicolon) { "}", 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