Skip to content

Commit 9a2a93f

Browse files
committed
[clang-format] Fix an assertion failure in RemoveSemicolon
Fixes #117290.
1 parent aa2d084 commit 9a2a93f

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

clang/lib/Format/Format.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2325,7 +2325,7 @@ class SemiRemover : public TokenAnalyzer {
23252325
private:
23262326
void removeSemi(TokenAnnotator &Annotator,
23272327
SmallVectorImpl<AnnotatedLine *> &Lines,
2328-
tooling::Replacements &Result) {
2328+
tooling::Replacements &Result, bool Children = false) {
23292329
auto PrecededByFunctionRBrace = [](const FormatToken &Tok) {
23302330
const auto *Prev = Tok.Previous;
23312331
if (!Prev || Prev->isNot(tok::r_brace))
@@ -2337,10 +2337,12 @@ class SemiRemover : public TokenAnalyzer {
23372337
const auto End = Lines.end();
23382338
for (auto I = Lines.begin(); I != End; ++I) {
23392339
const auto Line = *I;
2340-
removeSemi(Annotator, Line->Children, Result);
2340+
if (!Line->Children.empty())
2341+
removeSemi(Annotator, Line->Children, Result, /*Children=*/true);
23412342
if (!Line->Affected)
23422343
continue;
2343-
Annotator.calculateFormattingInformation(*Line);
2344+
if (!Children)
2345+
Annotator.calculateFormattingInformation(*Line);
23442346
const auto NextLine = I + 1 == End ? nullptr : I[1];
23452347
for (auto Token = Line->First; Token && !Token->Finalized;
23462348
Token = Token->Next) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27386,6 +27386,13 @@ TEST_F(FormatTest, RemoveSemicolon) {
2738627386
Style);
2738727387
#endif
2738827388

27389+
verifyFormat("auto sgf = [] {\n"
27390+
" ogl = {\n"
27391+
" a, b, c, d, e,\n"
27392+
" };\n"
27393+
"};",
27394+
Style);
27395+
2738927396
Style.TypenameMacros.push_back("STRUCT");
2739027397
verifyFormat("STRUCT(T, B) { int i; };", Style);
2739127398
}

0 commit comments

Comments
 (0)