diff --git a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp --- a/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp +++ b/clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp @@ -10,6 +10,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Lex/PPCallbacks.h" #include "clang/Lex/Preprocessor.h" +#include "llvm/ADT/STLExtras.h" #include @@ -61,16 +62,24 @@ if (IsMainModule) return 0; - // LLVM and clang headers are in the penultimate position. - if (Filename.startswith("llvm/") || Filename.startswith("llvm-c/") || - Filename.startswith("clang/") || Filename.startswith("clang-c/")) + auto FilenameStartsWith = [&](StringRef Search) { + return Filename.startswith(Search); + }; + + constexpr StringRef LLVMClangHeaders[] = {"llvm/", "llvm-c/", "clang/", + "clang-c/"}; + constexpr StringRef OtherHeaders[] = {"gtest/", "gmock/", "isl/", "json/"}; + + if (llvm::any_of(LLVMClangHeaders, FilenameStartsWith)) return 2; - // System headers are sorted to the end. - if (IsAngled || Filename.startswith("gtest/") || - Filename.startswith("gmock/")) + if (llvm::any_of(OtherHeaders, FilenameStartsWith)) return 3; + // System headers are sorted to the end. + if (IsAngled) + return 4; + // Other headers are inserted between the main module header and LLVM headers. return 1; } diff --git a/clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp b/clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp --- a/clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/llvm-include-order.cpp @@ -6,6 +6,7 @@ #include "gmock/foo.h" #include "i.h" #include +#include #include "llvm/a.h" #include "clang/b.h" #include "clang-c/c.h" // hi @@ -19,6 +20,7 @@ // CHECK-FIXES-NEXT: #include "llvm/a.h" // CHECK-FIXES-NEXT: #include "gmock/foo.h" // CHECK-FIXES-NEXT: #include "gtest/foo.h" +// CHECK-FIXES-NEXT: #include // CHECK-FIXES-NEXT: #include #include "b.h"