0

I installed a clangd plugin in VSCode to develop C++.

This plugin works well, but it shows some code error/waring in our project because we use a deprecated function in <zstd.h>.

include <zstd.h>

deprecated function

How can I mask this error without changing the code?


For example, I can ignore some warning in the VSCode's cpplint plugin by modifying .vscode/settings.json:

ignore some error on cpplint plugin

Can I do something like that to the VSCode's clangd plugin? thanks~

I try to use clang diagnostic, but it seems not work.

#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wdeprecated-attributes"
#include <zstd.h>
#pragma clang diagnostic pop

clang diagnostic don't work

TOMOCAT
  • 51
  • 1
  • 3
  • Its up to the extension's author to include the type of feature your asking about. You need to read the extensions readme file, and if it doesn't mention anything, then create an issue in the extensions repository (which is most likely a GitHub Repo). You can also write a bad review saying no way to ignore errors. The end goal is to get the authors attention. The other way, you can fork the repo, and add what ever you want to the extension. 95% of VS Code extensions are Licensed under the MIT or Apache-2.0 License, which are really really liberal licenses. – JΛYDΞV Nov 18 '22 at 06:27
  • To be clear VS Code itself will not include any such settings. – JΛYDΞV Nov 18 '22 at 06:27

1 Answers1

0

First, note that the reason for the error is not the function being deprecated, it's a parsing error ("an attribute list cannot appear here"). The note related to deprecation is just a comment that shows up in the hover, unrelated to the error diagnostic.

If you'd like to suppress the error, you can do it using https://clangd.llvm.org/config.html#suppress. For example, you could create a .clangd file in your project root containing:

Diagnostics:
  Suppress: attributes_not_allowed

(Note, attributes_not_allowed is the diagnostic code of the error from the first screenshot.)

However, suppressing the diagnostic is likely to just paper over an underlying problem that's likely related to your project's configuration. A better approach would be to fix the underlying issue. To do that, please review the project setup instructions and ensure your project has a compile_commands.json and clangd is finding it; if that doesn't resolve the issue, feel free to post clangd logs for further diagnosis.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194
  • thanks, it does work! But I don't know why this error `attributes_not_allowed` was reported, I will comment on it when I figure it out. – TOMOCAT Nov 22 '22 at 03:55