Index: clangd/ClangdServer.cpp =================================================================== --- clangd/ClangdServer.cpp +++ clangd/ClangdServer.cpp @@ -531,9 +531,15 @@ if (!C) // FIXME: Suppress diagnostics? Let the user know? C = CDB.getFallbackCommand(File); + // These flags are working for both gcc and clang-cl driver modes. // Inject the resource dir. // FIXME: Don't overwrite it if it's already there. C->CommandLine.push_back("-resource-dir=" + ResourceDir); + // Deprecations are often hidden for full-project build. They're useful in + // context. + C->CommandLine.push_back("-Wdeprecated"); + // Adding -Wdeprecated would trigger errors in projects what set -Werror. + C->CommandLine.push_back("-Wno-error=deprecated"); return std::move(*C); } Index: unittests/clangd/ClangdTests.cpp =================================================================== --- unittests/clangd/ClangdTests.cpp +++ unittests/clangd/ClangdTests.cpp @@ -43,6 +43,11 @@ namespace { +MATCHER(DeprecationWarning, "") { + return arg.Category == "Deprecations" && + arg.Severity == DiagnosticsEngine::Warning; +} + bool diagsContainErrors(const std::vector &Diagnostics) { for (auto D : Diagnostics) { if (D.Severity == DiagnosticsEngine::Error || @@ -963,6 +968,42 @@ Field(&CodeCompletion::Name, "baz"))); } +TEST(ClangdCompilecommand, DiagnosticDeprecated) { + std::string Code(R"cpp( + void foo() __attribute__((deprecated)); + void bar() { + foo(); + } + )cpp"); + auto SourcePath = testPath("source/foo.cpp"); + + MockFSProvider FS; + struct DiagConsumer : public DiagnosticsConsumer { + void onDiagnosticsReady(PathRef File, + std::vector Diagnostics) override { + Diags.insert(Diags.end(), Diagnostics.begin(), Diagnostics.end()); + } + + void reset() { + Diags.clear(); + } + + std::vector Diags; + } DiagConsumer; + MockCompilationDatabase CDB; + CDB.ExtraClangFlags.push_back("-Wno-deprecated"); + ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest()); + + runAddDocument(Server, SourcePath, Code); + EXPECT_THAT(DiagConsumer.Diags, ElementsAre(DeprecationWarning())); + DiagConsumer.reset(); + + CDB.ExtraClangFlags.push_back("-Werror"); + runAddDocument(Server, SourcePath, Code); + EXPECT_THAT(DiagConsumer.Diags, ElementsAre(DeprecationWarning())); +} + + } // namespace } // namespace clangd } // namespace clang