Skip to content

Commit a0458d9

Browse files
committed
[clang-format] Never remove braces in macro definitions
Fixes #56559. Differential Revision: https://reviews.llvm.org/D129921
1 parent 2b2e858 commit a0458d9

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Format/UnwrappedLineParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
539539
break;
540540
case tok::r_brace:
541541
if (OpeningBrace) {
542-
if (!Style.RemoveBracesLLVM ||
542+
if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
543543
!OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
544544
return false;
545545
}

clang/unittests/Format/FormatTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25803,6 +25803,13 @@ TEST_F(FormatTest, RemoveBraces) {
2580325803

2580425804
Style.ColumnLimit = 20;
2580525805

25806+
verifyFormat("int i;\n"
25807+
"#define FOO(a, b) \\\n"
25808+
" while (a) { \\\n"
25809+
" b; \\\n"
25810+
" }",
25811+
Style);
25812+
2580625813
verifyFormat("int ab = [](int i) {\n"
2580725814
" if (i > 0) {\n"
2580825815
" i = 12345678 -\n"

0 commit comments

Comments
 (0)