[PATCH] D51747: [clangd] Show deprecation diagnostics

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 14 03:25:50 PDT 2018


kadircet updated this revision to Diff 165462.
kadircet marked 2 inline comments as done.
kadircet added a comment.

- Add matchers to test.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51747

Files:
  clangd/ClangdServer.cpp
  unittests/clangd/ClangdTests.cpp


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<Diag> &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<Diag> Diagnostics) override {
+      Diags.insert(Diags.end(), Diagnostics.begin(), Diagnostics.end());
+    }
+
+    void reset() {
+      Diags.clear();
+    }
+
+    std::vector<Diag> 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
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);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51747.165462.patch
Type: text/x-patch
Size: 2537 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180914/7f79af78/attachment-0001.bin>


More information about the cfe-commits mailing list