clangd / clangd

clangd language server
https://clangd.llvm.org
Apache License 2.0
1.56k stars 64 forks source link

clangd complains on system includes while standalone clang-tidy does not #1587

Open alexolog opened 1 year ago

alexolog commented 1 year ago

Environment: MacOSX 13, VSCode with the clangd 15.0.6 plugin, CMake project generated compile_commands.json file.

clangd complains on every TEST, TEST_F, etc. GoogleTest macro, even though running clang-tidy as part of the build, using the same .clang-tidy files, produces no warnings.

Verbose log attached: log.log

HighCommander4 commented 1 year ago

Are the clang-tidy checks which are producing these diagnostics (cppcoreguidelines-avoid-non-const-global-variables, cert-err58-cpp, cppcoreguidelines-owning-memory) enabled or disabled in your clang-tidy configuration?

In other words, is it that clangd shouldn't be running these checks, or it should be running them but they should be passing?

alexolog commented 1 year ago

The checks are allowed, but they should not be shown on system headers.

Specifically, running clang-tidy 0test/main.cpp produces no warnings.

But explicitly enabling checking in system headers by running clang-tidy -system-headers 0test/main.cpp | grep -w warning: shows:

/Users/oren/work/server/0test/main.cpp:3:1: warning: initialization of 'test_info_' with static storage duration may throw an exception that cannot be caught [cert-err58-cpp]
/Users/oren/work/server/0test/main.cpp:3:1: warning: variable 'test_info_' provides global access to a non-const object; consider making the pointed-to data 'const' [cppcoreguidelines-avoid-non-const-global-variables]
/Users/oren/work/server/0test/main.cpp:3:1: warning: initializing non-owner argument of type 'testing::internal::TestFactoryBase *' with a newly created 'gsl::owner<>' [cppcoreguidelines-owning-memory]

clangd should behave like the former, not emitting warnings that originate in system headers.

HighCommander4 commented 1 year ago

The checks are allowed, but they should not be shown on system headers.

Ah, I see. I think that makes this a duplicate of #1448 then, which has been fixed in clangd 16.

alexolog commented 1 year ago

Interesting. Any idea when clangd 16 will be available? LLVM 16 is already on homebrew.

HighCommander4 commented 1 year ago

Any idea when clangd 16 will be available?

It's available via LLVM packages at https://github.com/llvm/llvm-project/releases/tag/llvmorg-16.0.0. As for a release on the clangd github releases page, I'm not sure; I filed #1567 recently, but I don't have the permissions to trigger it.