diff options
Diffstat (limited to 'clang-tools-extra')
-rw-r--r-- | clang-tools-extra/clangd/Diagnostics.cpp | 8 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index 919182d..7f1ab06 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -122,8 +122,12 @@ bool adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info, return SM.getIncludeLoc(SM.getFileID(SLoc)); }; for (auto IncludeLocation = GetIncludeLoc(DiagLoc); IncludeLocation.isValid(); - IncludeLocation = GetIncludeLoc(IncludeLocation)) - IncludeInMainFile = IncludeLocation; + IncludeLocation = GetIncludeLoc(IncludeLocation)) { + if (clangd::isInsideMainFile(IncludeLocation, SM)) { + IncludeInMainFile = IncludeLocation; + break; + } + } if (IncludeInMainFile.isInvalid()) return false; diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index c80dafe..2089c89 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -948,6 +948,15 @@ TEST(IgnoreDiags, FromNonWrittenSources) { EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); } +TEST(IgnoreDiags, FromNonWrittenInclude) { + TestTU TU = TestTU::withCode(""); + TU.ExtraArgs.push_back("--include=a.h"); + TU.AdditionalFiles = {{"a.h", "void main();"}}; + // The diagnostic "main must return int" is from the header, we don't attempt + // to render it in the main file as there is no written location there. + EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); +} + } // namespace } // namespace clangd |