Index: clang/lib/Format/Format.cpp =================================================================== --- clang/lib/Format/Format.cpp +++ clang/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: clang/unittests/Format/SortIncludesTest.cpp =================================================================== --- clang/unittests/Format/SortIncludesTest.cpp +++ clang/unittests/Format/SortIncludesTest.cpp @@ -117,6 +117,43 @@ "// clang-format on\n")); } +TEST_F(SortIncludesTest, SupportClangFormatOffCStyle) { + EXPECT_EQ("#include \n" + "#include \n" + "#include \n" + "/* clang-format off */\n" + "#include \n" + "#include \n" + "#include \n" + "/* clang-format on */\n", + sort("#include \n" + "#include \n" + "#include \n" + "/* clang-format off */\n" + "#include \n" + "#include \n" + "#include \n" + "/* clang-format on */\n")); + + // Not really turning it off + EXPECT_EQ("#include \n" + "#include \n" + "#include \n" + "/* clang-format offically */\n" + "#include \n" + "#include \n" + "#include \n" + "/* clang-format onwards */\n", + sort("#include \n" + "#include \n" + "#include \n" + "/* clang-format offically */\n" + "#include \n" + "#include \n" + "#include \n" + "/* clang-format onwards */\n")); +} + TEST_F(SortIncludesTest, IncludeSortingCanBeDisabled) { FmtStyle.SortIncludes = false; EXPECT_EQ("#include \"a.h\"\n"