[PATCH] D121352: [clang-format] Handle "// clang-format off" for RemoveBracesLLVM
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 10 13:31:08 PST 2022
This revision was automatically updated to reflect the committed changes.
Closed by commit rGe2b219bded11: [clang-format] Handle "// clang-format off" for RemoveBracesLLVM (authored by owenpan).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D121352/new/
https://reviews.llvm.org/D121352
Files:
clang/lib/Format/Format.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -24805,6 +24805,19 @@
"}",
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"
Index: clang/lib/Format/Format.cpp
===================================================================
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1808,7 +1808,8 @@
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));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D121352.414483.patch
Type: text/x-patch
Size: 1377 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220310/d446d248/attachment.bin>
More information about the cfe-commits
mailing list