[PATCH] D51747: [clangd] Show deprecation diagnostics
Kadir Cetinkaya via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 13 08:20:19 PDT 2018
kadircet updated this revision to Diff 165302.
kadircet added a comment.
This revision is now accepted and ready to land.
- Turn back to unit tests.
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
@@ -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<Diag> Diagnostics) override {
+ std::lock_guard<std::mutex> 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
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.165302.patch
Type: text/x-patch
Size: 2826 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180913/bd9bc7aa/attachment.bin>
More information about the cfe-commits
mailing list