diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 0cf4cdbeab31f3..0c3c4de6f00e1d 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2325,7 +2325,7 @@ class SemiRemover : public TokenAnalyzer { private: void removeSemi(TokenAnnotator &Annotator, SmallVectorImpl &Lines, - tooling::Replacements &Result) { + tooling::Replacements &Result, bool Children = false) { auto PrecededByFunctionRBrace = [](const FormatToken &Tok) { const auto *Prev = Tok.Previous; if (!Prev || Prev->isNot(tok::r_brace)) @@ -2337,10 +2337,12 @@ class SemiRemover : public TokenAnalyzer { const auto End = Lines.end(); for (auto I = Lines.begin(); I != End; ++I) { const auto Line = *I; - removeSemi(Annotator, Line->Children, Result); + if (!Line->Children.empty()) + removeSemi(Annotator, Line->Children, Result, /*Children=*/true); if (!Line->Affected) continue; - Annotator.calculateFormattingInformation(*Line); + if (!Children) + Annotator.calculateFormattingInformation(*Line); const auto NextLine = I + 1 == End ? nullptr : I[1]; for (auto Token = Line->First; Token && !Token->Finalized; Token = Token->Next) { diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 250e51b5421664..63d8dc2486e45f 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -27386,6 +27386,13 @@ TEST_F(FormatTest, RemoveSemicolon) { Style); #endif + verifyFormat("auto sgf = [] {\n" + " ogl = {\n" + " a, b, c, d, e,\n" + " };\n" + "};", + Style); + Style.TypenameMacros.push_back("STRUCT"); verifyFormat("STRUCT(T, B) { int i; };", Style); }