Index: clang-tidy/llvm/IncludeOrderCheck.cpp =================================================================== --- clang-tidy/llvm/IncludeOrderCheck.cpp +++ clang-tidy/llvm/IncludeOrderCheck.cpp @@ -73,6 +73,9 @@ SourceLocation HashLoc, const Token &IncludeTok, StringRef FileName, bool IsAngled, CharSourceRange FilenameRange, const FileEntry *File, StringRef SearchPath, StringRef RelativePath, const Module *Imported) { + if (SM.getFileID(HashLoc) != SM.getMainFileID()) + return; + // We recognize the first include as a special main module header and want // to leave it in the top position. IncludeDirective ID = {HashLoc, FilenameRange, FileName, IsAngled, false}; Index: test/clang-tidy/Inputs/Headers/cross-file-c.h =================================================================== --- /dev/null +++ test/clang-tidy/Inputs/Headers/cross-file-c.h @@ -0,0 +1,2 @@ + +#include "cross-file-b.h" Index: test/clang-tidy/llvm-include-order.cpp =================================================================== --- test/clang-tidy/llvm-include-order.cpp +++ test/clang-tidy/llvm-include-order.cpp @@ -35,3 +35,8 @@ // CHECK-FIXES: #include "a.h" // CHECK-FIXES-NEXT: #include "b.h" + +// CHECK-MESSAGES-NOT: [[@LINE+1]]:1: warning: #includes are not sorted properly +#include "cross-file-a.h" + +#include "cross-file-c.h"