[PATCH] D121352: [clang-format] Handle "// clang-format off" for RemoveBracesLLVM
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)); 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)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D121352: [clang-format] Handle "// clang-format off" for RemoveBracesLLVM
owenpan created this revision. owenpan added reviewers: MyDeveloperDay, curdeius, HazardyKnusperkeks. owenpan added a project: clang-format. Herald added a project: All. owenpan requested review of this revision. Herald added a project: clang. Herald added a subscriber: cfe-commits. Repository: rG LLVM Github Monorepo 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)); 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)); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits