Skip to content

Commit

Permalink
[clang-format] Handle "// clang-format off" for RemoveBracesLLVM
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D121352
  • Loading branch information
owenca committed Mar 10, 2022
1 parent 19c6098 commit e2b219b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
3 changes: 2 additions & 1 deletion clang/lib/Format/Format.cpp
Expand Up @@ -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));
Expand Down
13 changes: 13 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Expand Up @@ -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"
Expand Down

0 comments on commit e2b219b

Please sign in to comment.