-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UnusedIncludes dosen't check angle includes #1774
Comments
This has come up in clangd/vscode-clangd#452 as well. I suspect it may be intentional, though I don't know the motivation for it. Perhaps some folks who worked on include-cleaner such as @VitaNuo or @kadircet can provide some details. |
Clangd currently doesn't support detecting what's used in transitive includes. You can see it with such a setup:
#pragma once
void mylib_specific_function();
#pragma once
#include "super_specific_header.hpp"
// doc says you should use this umbrella header to pull the whole thing
// but you'll get a warning if you used "" instead of <>
#include "mylib.h"
int main() { mylib_specific_function(); } So clangd simply ignores all angle includes (except from std) to not produce false positives with this common pattern. See here if you want to work on this. |
Assuming that an angle include is a system header doesn't seem justified, since, when resolving an angle include, the compiler does look at regular entries of the include search path after looking at system entries. A more accurate check for "system header" would be that it was found in an entry of the include search path specified using |
I stumbled upon this behavior. Was rather confusing. I would definitely like (and expected) includes using <> to be reported as unused just like includes with "". |
@kadircet Is this check still needed? Standalone clang-include-cleaner doesn't have it, so I suspect the new include-cleaner lib is robust enough to handle system includes (at least for the people willing to use it). If we want to conservatively avoid analyzing system headers we should at least switch to CharacteristicKind (-isystem) and make this a config option with a conservative default. The original intent was to disable analysis of weird-layout libraries like C++ standard library, C standard library, posix etc. (I think this was using the old clangd-specific implementation which was more limited). |
I don't think that's it. Standard library headers are handled separately. This was done to avoid errors with umbrella headers. It'd be nice to keep it this behavior at least behind an option so I don't get spammed with warnings for third party libs, but still enjoy the check on my code that I include with |
configured using
cmake -S . -B build -G 'Ninja' -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
CMakeLists.txt
main.cpp
hello.hpp
.clangd
Logs
for
#include "hello.hpp"
for
#include <hello.hpp>
System information
Output of
clangd --version
:Editor/LSP plugin:
Operating system:
The text was updated successfully, but these errors were encountered: