Now that IWYU pragma: keep supresses the warning for unused header, it should
be possible to suggest the user both removing the header and adding a pragma to
keep it instead.
Details
- Reviewers
sammccall
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Nice!
clang-tools-extra/clangd/IncludeCleaner.cpp | ||
---|---|---|
212 | I think we should be a bit more direct about the *content* that we're matching here, rather than the coordinates. e.g. the current logic is broken in various ways if the directive is split over physical lines, and dealing with coordinates makes it both hard to fix and detect. And it seems like you're going to offer a fix erasing any existing trailing comment. Possibly there are other unexpected patterns where the code might get mangled too. Maybe more like: StringRef RestOfLine = Code.substr(HashOffset).take_until('\n' || '\r'); if (!RestOfLine.consume_front("#")) return fail; RestOfLine = RestOfLine.ltrim(); // and consume the rest of the stuff we expect on the line if (RestOfLine.ltrim().empty()) { return { offsetToPosition(Code, RestOfLine.begin() - Code.data(), offsetToPosition(Code, RestOfLine.end() - Code.data(), }; } | |
223 | this is incorrect for #include \ <foo.h> (Happy if it works or rejects this case, but it shouldn't silently do the wrong thing.) | |
227 | I'd expect error cases to be handled somehow, the fact that this function always succeeds is suspicious | |
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp | ||
1616–1618 | nit: insert->pragma_keep? |
I think we should be a bit more direct about the *content* that we're matching here, rather than the coordinates.
e.g. the current logic is broken in various ways if the directive is split over physical lines, and dealing with coordinates makes it both hard to fix and detect.
And it seems like you're going to offer a fix erasing any existing trailing comment.
Possibly there are other unexpected patterns where the code might get mangled too.
Maybe more like: