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 @@ -2481,9 +2481,13 @@ // { // return i + 1; // } - if (Next->Next && Next->Next->is(tok::identifier) && - Line.Last->isNot(tok::semi)) - return true; + if (Next->Next && Next->Next->is(tok::identifier)) { + const FormatToken *Last = Line.Last; + if (Last && Last->is(tok::comment)) + Last = Last->getPreviousNonComment(); + if (Last && Last->isNot(tok::semi)) + return true; + } for (const FormatToken *Tok = Next->Next; Tok && Tok != Next->MatchingParen; Tok = Tok->Next) { if (Tok->is(TT_TypeDeclarationParen)) 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 @@ -8252,6 +8252,9 @@ verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n" " ABSL_GUARDED_BY(mutex) = {};", getGoogleStyleWithColumns(40)); + verifyFormat("Tttttttttttttttttttttttt ppppppppppppppp\n" + " ABSL_GUARDED_BY(mutex); // comment", + getGoogleStyleWithColumns(40)); Style = getGNUStyle();