This revision was automatically updated to reflect the committed changes. Closed by commit rL355266: [clang-format] clang-format off/on not respected when using C Style comments (authored by paulhoad, committed by ). Herald added a project: LLVM.
Changed prior to commit: https://reviews.llvm.org/D58819?vs=188931&id=189039#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D58819/new/ https://reviews.llvm.org/D58819 Files: cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/SortIncludesTest.cpp Index: cfe/trunk/lib/Format/Format.cpp =================================================================== --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/lib/Format/Format.cpp @@ -1786,9 +1786,10 @@ Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev); StringRef Trimmed = Line.trim(); - if (Trimmed == "// clang-format off") + if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off */") FormattingOff = true; - else if (Trimmed == "// clang-format on") + else if (Trimmed == "// clang-format on" || + Trimmed == "/* clang-format on */") FormattingOff = false; const bool EmptyLineSkipped = Index: cfe/trunk/unittests/Format/SortIncludesTest.cpp =================================================================== --- cfe/trunk/unittests/Format/SortIncludesTest.cpp +++ cfe/trunk/unittests/Format/SortIncludesTest.cpp @@ -117,6 +117,43 @@ "// clang-format on\n")); } +TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) { + EXPECT_EQ("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format off */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format on */\n", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format off */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format on */\n")); + + // Not really turning it off + EXPECT_EQ("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format offically */\n" + "#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format onwards */\n", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format offically */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format onwards */\n")); +} + TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { FmtStyle.SortIncludes = false; EXPECT_EQ("#include \"a.h\"\n"
Index: cfe/trunk/lib/Format/Format.cpp =================================================================== --- cfe/trunk/lib/Format/Format.cpp +++ cfe/trunk/lib/Format/Format.cpp @@ -1786,9 +1786,10 @@ Code.substr(Prev, (Pos != StringRef::npos ? Pos : Code.size()) - Prev); StringRef Trimmed = Line.trim(); - if (Trimmed == "// clang-format off") + if (Trimmed == "// clang-format off" || Trimmed == "/* clang-format off */") FormattingOff = true; - else if (Trimmed == "// clang-format on") + else if (Trimmed == "// clang-format on" || + Trimmed == "/* clang-format on */") FormattingOff = false; const bool EmptyLineSkipped = Index: cfe/trunk/unittests/Format/SortIncludesTest.cpp =================================================================== --- cfe/trunk/unittests/Format/SortIncludesTest.cpp +++ cfe/trunk/unittests/Format/SortIncludesTest.cpp @@ -117,6 +117,43 @@ "// clang-format on\n")); } +TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) { + EXPECT_EQ("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format off */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format on */\n", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format off */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format on */\n")); + + // Not really turning it off + EXPECT_EQ("#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format offically */\n" + "#include <a>\n" + "#include <b>\n" + "#include <c>\n" + "/* clang-format onwards */\n", + sort("#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format offically */\n" + "#include <b>\n" + "#include <a>\n" + "#include <c>\n" + "/* clang-format onwards */\n")); +} + TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { FmtStyle.SortIncludes = false; EXPECT_EQ("#include \"a.h\"\n"
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits