Skip to content

Commit feba3d9

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

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3901,6 +3901,11 @@ bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const {
39013901
}
39023902

39033903
void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
3904+
if (Line.Computed)
3905+
return;
3906+
3907+
Line.Computed = true;
3908+
39043909
for (AnnotatedLine *ChildLine : Line.Children)
39053910
calculateFormattingInformation(*ChildLine);
39063911

clang/lib/Format/TokenAnnotator.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,9 @@ class AnnotatedLine {
182182
/// \c True if this line contains a macro call for which an expansion exists.
183183
bool ContainsMacroCall = false;
184184

185+
/// \c True if calculateFormattingInformation() has been called on this line.
186+
bool Computed = false;
187+
185188
/// \c True if this line should be formatted, i.e. intersects directly or
186189
/// indirectly with one of the input ranges.
187190
bool Affected;

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)