Skip to content

Commit

Permalink
[clang-format] Fix an assertion failure in RemoveSemicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
owenca committed Nov 24, 2024
1 parent aa2d084 commit 9a2a93f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions clang/lib/Format/Format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2325,7 +2325,7 @@ class SemiRemover : public TokenAnalyzer {
private:
void removeSemi(TokenAnnotator &Annotator,
SmallVectorImpl<AnnotatedLine *> &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))
Expand All @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 9a2a93f

Please sign in to comment.