[clang] e2b219b - [clang-format] Handle "// clang-format off" for RemoveBracesLLVM
via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 10 13:31:01 PST 2022
Author: owenca
Date: 2022-03-10T13:30:53-08:00
New Revision: e2b219bded113160500d1084f87ee11ec926877b
URL: https://github.com/llvm/llvm-project/commit/e2b219bded113160500d1084f87ee11ec926877b
DIFF: https://github.com/llvm/llvm-project/commit/e2b219bded113160500d1084f87ee11ec926877b.diff
LOG: [clang-format] Handle "// clang-format off" for RemoveBracesLLVM
Differential Revision: https://reviews.llvm.org/D121352
Added:
Modified:
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 6c2765c038436..a8b8efb5b22f5 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1808,7 +1808,8 @@ class BracesRemover : public TokenAnalyzer {
removeBraces(Line->Children, Result);
if (!Line->Affected)
continue;
- for (FormatToken *Token = Line->First; Token; Token = Token->Next) {
+ for (FormatToken *Token = Line->First; Token && !Token->Finalized;
+ Token = Token->Next) {
if (!Token->Optional)
continue;
assert(Token->isOneOf(tok::l_brace, tok::r_brace));
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 1d9b158ee6475..dab8f83fffe3c 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -24805,6 +24805,19 @@ TEST_F(FormatTest, RemoveBraces) {
"}",
Style);
+ verifyFormat("// clang-format off\n"
+ "// comment\n"
+ "while (i > 0) { --i; }\n"
+ "// clang-format on\n"
+ "while (j < 0)\n"
+ " ++j;",
+ "// clang-format off\n"
+ "// comment\n"
+ "while (i > 0) { --i; }\n"
+ "// clang-format on\n"
+ "while (j < 0) { ++j; }",
+ Style);
+
verifyFormat("if (a)\n"
" b; // comment\n"
"else if (c)\n"
More information about the cfe-commits
mailing list