[PATCH] D51747: [clangd] Implement deprecation diagnostics with lower severity.

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 13 05:59:34 PDT 2018


kadircet updated this revision to Diff 165266.
kadircet marked an inline comment as done.
kadircet added a comment.

- Do not show up as errors even on codebases with -Werror.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D51747

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


Index: unittests/clangd/ClangdUnitTests.cpp
===================================================================
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -220,6 +220,44 @@
   }
 }
 
+TEST(DiagnosticsTest, 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");
+  EXPECT_THAT(
+      TestTU::withCode(Test.code()).build().getDiagnostics(),
+      ElementsAre(
+          AllOf(Diag(Test.range("foo"), "'foo' is deprecated"),
+                WithNote(
+                    Diag(Test.range("foodeprecation"),
+                         "'foo' has been explicitly marked deprecated here"))),
+          AllOf(Diag(Test.range("x"), "'x' is deprecated"),
+                WithNote(
+                    Diag(Test.range("xdeprecation"),
+                         "'x' has been explicitly marked deprecated here")))));
+}
+
+TEST(DiagnosticsTest, DiagnosticDeprecatedWithFix) {
+  Annotations Test(R"cpp(
+    void bar();
+    void foo() __attribute__((deprecated("", "bar")));
+    int main() {
+      $deprecated[[foo]]();
+    }
+  )cpp");
+  EXPECT_THAT(TestTU::withCode(Test.code()).build().getDiagnostics(),
+              ElementsAre(WithFix(Fix(Test.range("deprecated"), "bar",
+                                      "change 'foo' to 'bar'"))));
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang
Index: clangd/ClangdServer.cpp
===================================================================
--- clangd/ClangdServer.cpp
+++ clangd/ClangdServer.cpp
@@ -531,9 +531,12 @@
   if (!C) // FIXME: Suppress diagnostics? Let the user know?
     C = CDB.getFallbackCommand(File);
 
-  // Inject the resource dir.
+  // Inject the resource dir. These flags are working for both gcc and clang-cl
+  // driver modes.
   // FIXME: Don't overwrite it if it's already there.
   C->CommandLine.push_back("-resource-dir=" + ResourceDir);
+  C->CommandLine.push_back("-Wdeprecated");
+  C->CommandLine.push_back("-Wno-error=deprecated");
   return std::move(*C);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D51747.165266.patch
Type: text/x-patch
Size: 2251 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/4d239b07/attachment-0001.bin>


More information about the cfe-commits mailing list