Skip to content

Commit 853fb0a

Browse files
authored
[clang-format] Don't alter SpacesRequiredBefore of finalized tokens (#69897)
Fixes #69237.
1 parent 2f15082 commit 853fb0a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3544,7 +3544,7 @@ void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
35443544
}
35453545
}
35463546
}
3547-
} else if (Current->SpacesRequiredBefore == 0 &&
3547+
} else if (!Current->Finalized && Current->SpacesRequiredBefore == 0 &&
35483548
spaceRequiredBefore(Line, *Current)) {
35493549
Current->SpacesRequiredBefore = 1;
35503550
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26459,6 +26459,25 @@ TEST_F(FormatTest, AllowBreakBeforeNoexceptSpecifier) {
2645926459
Style);
2646026460
}
2646126461

26462+
TEST_F(FormatTest, PPBranchesInBracedInit) {
26463+
verifyFormat("A a_{kFlag1,\n"
26464+
"#if BUILD_FLAG\n"
26465+
" kFlag2,\n"
26466+
"#else\n"
26467+
" kFlag3,\n"
26468+
"#endif\n"
26469+
" kFlag4};",
26470+
"A a_{\n"
26471+
" kFlag1,\n"
26472+
"#if BUILD_FLAG\n"
26473+
" kFlag2,\n"
26474+
"#else\n"
26475+
" kFlag3,\n"
26476+
"#endif\n"
26477+
" kFlag4\n"
26478+
"};");
26479+
}
26480+
2646226481
} // namespace
2646326482
} // namespace test
2646426483
} // namespace format

0 commit comments

Comments
 (0)