Skip to content

Commit d33d563

Browse files
authored
[clang-format] Fix a bug in SpaceInEmptyBlock option (#85508)
Fixes #84695.
1 parent a2bad75 commit d33d563

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

clang/lib/Format/TokenAnnotator.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4271,6 +4271,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
42714271
return Left.is(tok::hash);
42724272
if (Left.isOneOf(tok::hashhash, tok::hash))
42734273
return Right.is(tok::hash);
4274+
if (Left.is(BK_Block) && Right.is(tok::r_brace) &&
4275+
Right.MatchingParen == &Left && Line.Children.empty()) {
4276+
return Style.SpaceInEmptyBlock;
4277+
}
42744278
if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
42754279
(Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
42764280
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {

clang/unittests/Format/FormatTest.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6959,6 +6959,10 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
69596959
"else if (b) { }\n"
69606960
"else { }",
69616961
Style);
6962+
6963+
Style = getLLVMStyle(FormatStyle::LK_CSharp);
6964+
Style.SpaceInEmptyBlock = true;
6965+
verifyFormat("Event += () => { };", Style);
69626966
}
69636967

69646968
TEST_F(FormatTest, FormatBeginBlockEndMacros) {

0 commit comments

Comments
 (0)