llvm / llvm/llvm-project

[clang-tidy] misc-include-header fails to report thread header is missing (while clandg correctly report it)

Open
#169,667 2 comments 0 reactions 0 assignees View on GitHub
clang-include-cleaner
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

`clang-tidy-21` check `misc-include-header` fails to report that `#include ` is missing.
`clangd-21` on the other hand will report him as missing as expected.

Reproduction :

Taken from repository : https://github.com/blabdouze/misc-include-cleaner-not-reported/tree/bug/clangd-missmatch-tidy-include

```cpp
#pragma once

#include
#include

class A {
public:
A();
private:
std::vector myVector;
std::thread myThread;
};
```

```cpp
#include "A.hpp"

A::A() {
// Report warning in clangd but not with clang-tidy
myThread = std::thread([] {});
// Reports warning: no header providing "std::vector" is directly included [misc-include-cleaner]
myVector = std::vector();
}
```

clang-tidy-21 output :

```
root@bd29cfc504f4:/workspaces/misc-include-cleaner-not-reported# clang-tidy-21 -p=build A.cpp
109 warnings generated.
/workspaces/misc-include-cleaner-not-reported/A.cpp:7:21: warning: no header providing "std::vector" is directly included [misc-include-cleaner]
2 |
3 | A::A() {
4 | // Report warning in clangd but not with clang-tidy
5 | myThread = std::thread([] {});
6 | // Reports warning: no header providing "std::vector" is directly included [misc-include-cleaner]
7 | myVector = std::vector();
| ^
Suppressed 108 warnings (108 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
```

clangd-21 with this configuration inside VS Code :

```
---
Diagnostics:
MissingIncludes: Strict
UnusedIncludes: Strict
```

Image

Image

It seems that this case only trigger if you are assigning a thread to a member class variable. Declaring a new thread will trigger the warning as expected :

```cpp
#include "A.hpp"

A::A() {
// Report warning in clangd but not with clang-tidy
auto working = std::thread([] {});
// Reports warning: no header providing "std::vector" is directly included [misc-include-cleaner]
myVector = std::vector();
}
```

```
root@bd29cfc504f4:/workspaces/misc-include-cleaner-not-reported# clang-tidy-21 -p=build A.cpp
110 warnings generated.
/workspaces/misc-include-cleaner-not-reported/A.cpp:5:19: warning: no header providing "std::thread" is directly included [misc-include-cleaner]
2 |
3 | A::A() {
4 | // Works as expected
5 | auto m = std::thread([] {});
| ^
/workspaces/misc-include-cleaner-not-reported/A.cpp:7:21: warning: no header providing "std::vector" is directly included [misc-include-cleaner]
2 |
3 | A::A() {
4 | // Works as expected
5 | auto m = std::thread([] {});
6 | // Reports warning: no header providing "std::vector" is directly included [misc-include-cleaner]
7 | myVector = std::vector();
| ^
Suppressed 108 warnings (108 in non-user code).
Use -header-filter=.* to display errors from all non-system headers. Use -system-headers to display errors from system headers as well.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.