Due to my job, I have to develop software with only C but not C .
It will be good that when I write class A {};
Vscode will display an error or a warning.
Now I use clangd, it will be great if some settings can satisfy.
CodePudding user response:
Clangd will correctly issue diagnostics for C -only constructs, if it's parsing your file in C mode.
So it's a matter of making sure clangd is parsing your files in the correct language mode.
If your file's extension is unambiguously a C-language extension (for example, .c
), then clang should parse the file in C mode automatically.
If the extension is ambiguous, like .h
, then clangd attempts to choose the language heuristically, which can sometimes give a wrong answer. In this case, you can specify the language explicitly in the file's compile command, for example by adding -x c-header
to specify "parse as a C header".
One way to do this is using CompileFlags:
Add:
in the clangd config file. For example, to specify that all .h
files in the project are C headers, you might add the following to the project .clangd
file:
If:
PathMatch: .*\.h
CompileFlags:
Add: [-xc-header]