Skip to content

Commit

Permalink
[clang-format] Fix a bug in SpaceInEmptyBlock option (#85508)
Browse files Browse the repository at this point in the history
Fixes #84695.
  • Loading branch information
owenca committed Mar 16, 2024
1 parent a2bad75 commit d33d563
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4271,6 +4271,10 @@ bool TokenAnnotator::spaceRequiredBetween(const AnnotatedLine &Line,
return Left.is(tok::hash);
if (Left.isOneOf(tok::hashhash, tok::hash))
return Right.is(tok::hash);
if (Left.is(BK_Block) && Right.is(tok::r_brace) &&
Right.MatchingParen == &Left && Line.Children.empty()) {
return Style.SpaceInEmptyBlock;
}
if ((Left.is(tok::l_paren) && Right.is(tok::r_paren)) ||
(Left.is(tok::l_brace) && Left.isNot(BK_Block) &&
Right.is(tok::r_brace) && Right.isNot(BK_Block))) {
Expand Down
4 changes: 4 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6959,6 +6959,10 @@ TEST_F(FormatTest, PutEmptyBlocksIntoOneLine) {
"else if (b) { }\n"
"else { }",
Style);

Style = getLLVMStyle(FormatStyle::LK_CSharp);
Style.SpaceInEmptyBlock = true;
verifyFormat("Event += () => { };", Style);
}

TEST_F(FormatTest, FormatBeginBlockEndMacros) {
Expand Down

0 comments on commit d33d563

Please sign in to comment.