diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -2605,7 +2605,7 @@ ArrayRef Ranges, StringRef FileName, unsigned *Cursor) { tooling::Replacements Replaces; - if (!Style.SortIncludes) + if (!Style.SortIncludes || Style.DisableFormat) return Replaces; if (isLikelyXml(Code)) return Replaces; diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -9,6 +9,7 @@ #include "FormatTestUtils.h" #include "clang/Format/Format.h" #include "llvm/ADT/None.h" +#include "llvm/ADT/StringRef.h" #include "llvm/Support/Debug.h" #include "gtest/gtest.h" @@ -1034,6 +1035,16 @@ EXPECT_EQ(Expected, sort(Code, "a.cpp", 1)); } +TEST_F(SortIncludesTest, DisableFormatDisablesIncludeSorting) { + StringRef Sorted = "#include \n" + "#include \n"; + StringRef Unsorted = "#include \n" + "#include \n"; + EXPECT_EQ(Sorted, sort(Unsorted)); + FmtStyle.DisableFormat = true; + EXPECT_EQ(Unsorted, sort(Unsorted, "input.cpp", 0)); +} + } // end namespace } // end namespace format } // end namespace clang