| Issue |
234965
|
| Summary |
[clang-tidy] misc-include-cleaner: missing include not reported when an implicit reference precedes the explicit one (DeduplicateFindings)
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
kmate19
|
version: clang-tidy 22.1.6, Windows, MSVC STL
minimal repro:
```cpp
// id.h
#pragma once
#include <string>
struct Id {
explicit Id(std::string s) : s(std::move(s)) {}
std::string const &path() const { return s; }
std::string s;
};
// a.h
#pragma once
#include <string>
#include "id.h"
struct A { void f(std::string const &p); };
// main.cpp
#include <string>
#include "a.h"
void A::f(std::string const &p) { (void)Id(p).path(); }
void g(Id const &id); // id.h not directly included
```
running:
```console
clang-tidy --checks='-*,misc-include-cleaner' main.cpp -- -std=c++20
```
expected: `no header providing "Id" is directly included` (clangd reports it correctly)
actual: produces no output
if things in main are reordered like so:
```cpp
// main.cpp
#include <string>
#include "a.h"
void g(Id const &id);
void A::f(std::string const &p) { (void)Id(p).path(); }
```
running the same command outputs the following:
```console
main.cpp:3:8: warning: no header providing "Id" is directly included [misc-include-cleaner]
2 | #include "a.h"
3 | void g(Id const &id);
| ^
```
if run with:
```console
clang-tidy --checks='-*,misc-include-cleaner' --config="{CheckOptions: {misc-include-cleaner.DeduplicateFindings: false}}" main.cpp -- -std=c++20
```
both usages are reported as warnings, regardless of order, so for anyone that has this issue a workaround is to disable DeduplicateFindings for now.
the issue seems to be in [IncludeCleanerCheck.cpp L153-174](https://github.com/llvm/llvm-project/blob/f79c50183750b703ca47dfe1d041362de53234c7/clang-tools-extra/clang-tidy/misc/IncludeCleanerCheck.cpp#L153-L174), where only the explicit references are ever reported, but the implicit references still mark symbols as seen, skipping any further occurences
same root cause as #169667, the std::thread usage
#196767 is rewriting this part of the code that should fix this, since the dedup runs over MissingRefs only, this repro could be added as a regression test.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs