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 @@ -963,6 +963,63 @@ Field(&CodeCompletion::Name, "baz"))); } +TEST(ClangdCompilecommand, DiagnosticDeprecated) { + Annotations Test(R"cpp( + void foo() __attribute__(($foodeprecation[[deprecated]])); + class A { + public: + int x __attribute__(($xdeprecation[[deprecated]])); + }; + int main() { + $foo[[foo]](); + return A().$x[[x]]; + } + )cpp"); + auto SourcePath = testPath("source/foo.cpp"); + + MockFSProvider FS; + struct DiagConsumer : public DiagnosticsConsumer { + void onDiagnosticsReady(PathRef File, + std::vector Diagnostics) override { + std::lock_guard Lock(Mutex); + for(const Diag& D : Diagnostics) { + if(D.Category == "Deprecations") { + HadDeprecation = true; + if (D.Severity == DiagnosticsEngine::Error || + D.Severity == DiagnosticsEngine::Fatal) + HadDeprecationAsError = true; + } + } + } + + bool workedAsExpected() { + return !HadDeprecationAsError && HadDeprecation; + } + + void reset() { + HadDeprecation = false; + HadDeprecationAsError = false; + } + + private: + std::mutex Mutex; + bool HadDeprecationAsError = false; + bool HadDeprecation = false; + } DiagConsumer; + MockCompilationDatabase CDB; + CDB.ExtraClangFlags.push_back("-Wno-deprecated"); + ClangdServer Server(CDB, FS, DiagConsumer, ClangdServer::optsForTest()); + + runAddDocument(Server, SourcePath, Test.code()); + EXPECT_TRUE(DiagConsumer.workedAsExpected()); + DiagConsumer.reset(); + + CDB.ExtraClangFlags.push_back("-Werror"); + runAddDocument(Server, SourcePath, Test.code()); + EXPECT_TRUE(DiagConsumer.workedAsExpected()); +} + + } // namespace } // namespace clangd } // namespace clang