[clang] a0458d9 - [clang-format] Never remove braces in macro definitions
via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 16 13:11:20 PDT 2022
Author: owenca
Date: 2022-07-16T13:11:10-07:00
New Revision: a0458d92e9e7b279c9ff491429aad86ccedee7c4
URL: https://github.com/llvm/llvm-project/commit/a0458d92e9e7b279c9ff491429aad86ccedee7c4
DIFF: https://github.com/llvm/llvm-project/commit/a0458d92e9e7b279c9ff491429aad86ccedee7c4.diff
LOG: [clang-format] Never remove braces in macro definitions
Fixes #56559.
Differential Revision: https://reviews.llvm.org/D129921
Added:
Modified:
clang/lib/Format/UnwrappedLineParser.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp
index 97c3d86282a02..bfacfa3e3595f 100644
--- a/clang/lib/Format/UnwrappedLineParser.cpp
+++ b/clang/lib/Format/UnwrappedLineParser.cpp
@@ -539,7 +539,7 @@ bool UnwrappedLineParser::parseLevel(const FormatToken *OpeningBrace,
break;
case tok::r_brace:
if (OpeningBrace) {
- if (!Style.RemoveBracesLLVM ||
+ if (!Style.RemoveBracesLLVM || Line->InPPDirective ||
!OpeningBrace->isOneOf(TT_ControlStatementLBrace, TT_ElseLBrace)) {
return false;
}
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 08cfdbe2cc7a1..6b7454f9afd70 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25803,6 +25803,13 @@ TEST_F(FormatTest, RemoveBraces) {
Style.ColumnLimit = 20;
+ verifyFormat("int i;\n"
+ "#define FOO(a, b) \\\n"
+ " while (a) { \\\n"
+ " b; \\\n"
+ " }",
+ Style);
+
verifyFormat("int ab = [](int i) {\n"
" if (i > 0) {\n"
" i = 12345678 -\n"
More information about the cfe-commits
mailing list