[all-commits] [llvm/llvm-project] 5574a5: [include-cleaner] don't consider the associated he...
Sam McCall via All-commits
all-commits at lists.llvm.org
Wed Jun 19 06:29:26 PDT 2024
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 5574a5894fdb7f9a46a4fbe6c8970fd39890dc9b
https://github.com/llvm/llvm-project/commit/5574a5894fdb7f9a46a4fbe6c8970fd39890dc9b
Author: Sam McCall <sam.mccall at gmail.com>
Date: 2024-06-19 (Wed, 19 Jun 2024)
Changed paths:
M clang-tools-extra/include-cleaner/lib/Record.cpp
M clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
Log Message:
-----------
[include-cleaner] don't consider the associated header unused (#67228)
Loosely, the "associated header" of `foo.cpp` is `foo.h`.
It should be included, many styles include it first.
So far we haven't special cased it in any way, and require this include
to be justified. e.g. if foo.cpp defines a function declared in foo.h,
then the #include is allowed to check these declarations match.
However this doesn't really align with what users want:
- people reasonably want to include the associated header for the
side-effect of validating that it compiles.
In the degenerate case, `lib.cpp`is just `#include "lib.h"` (see bug)
- That `void foo(){}` IWYU-uses `void foo();` is a bit artificial, and
most users won't internalize this. Instead they'll stick with the
simpler model "include the header that defines your API".
In the rare cases where these give different answers[1], our current
behavior is a puzzling special case from the user POV.
It is more user-friendly to accept both models.
- even where this diagnostic is a true positive (defs don't match header
decls) the diagnostic does not communicate this usefully.
Fixes https://github.com/llvm/llvm-project/issues/67140
[1] Example of an associated header that's not IWYU-used:
```
// http.h
inline URL buildHttpURL(string host, int port, string path) {
return "http://" + host + ":" + port + "/" + path;
}
// http.cpp
class HTTPURLHandler : URLHandler { ... };
REGISTER_URL_HANDLER("http", HTTPURLHandler);
```
To unsubscribe from these emails, change your notification settings at https://github.com/llvm/llvm-project/settings/notifications
More information about the All-commits
mailing list