| Issue |
165551
|
| Summary |
[clang-tidy] misc-include-cleaner warnings are not displayed in header file unless explicity checked
|
| Labels |
clang-tidy
|
| Assignees |
|
| Reporter |
blabdouze
|
Tested with clang-tidy-21
Given this project : https://github.com/blabdouze/misc-include-cleaner-not-reported , clang-tidy doesn't report misc-include-cleaner warnings if clang-tidy is not called directly on the header file (but others warnings works fine).
Other warnings appears when checking main.cpp with header filter set to .* :
```
test> clang-tidy-21 -header-filter=.* -p=build main.cpp
136 warnings generated.
/workspace/build/test/A.hpp:6:26: warning: function 'AFunc' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
6 | std::vector<std::string> AFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/A.hpp:6:26: note: mark the definition as 'inline'
6 | std::vector<std::string> AFunc() { return std::vector<std::string>(); }
| ^
| inline
/workspace/build/test/B.hpp:5:26: warning: function 'BFunc' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/B.hpp:5:26: note: mark the definition as 'inline'
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
| inline
Suppressed 134 warnings (134 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.
```
If run against the header directly, everything works fine :
```
test> clang-tidy-21 -header-filter=.* -p=build B.hpp
139 warnings generated.
/workspace/build/test/A.hpp:6:26: warning: function 'AFunc' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
6 | std::vector<std::string> AFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/A.hpp:6:26: note: mark the definition as 'inline'
6 | std::vector<std::string> AFunc() { return std::vector<std::string>(); }
| ^
| inline
/workspace/build/test/B.hpp:3:1: warning: included header A.hpp is not used directly [misc-include-cleaner]
3 | #include "A.hpp"
| ^~~~~~~~~~~~~~~~
4 |
/workspace/build/test/B.hpp:5:6: warning: no header providing "std::vector" is directly included [misc-include-cleaner]
3 | #include "A.hpp"
4 |
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/B.hpp:5:18: warning: no header providing "std::string" is directly included [misc-include-cleaner]
3 | #include "A.hpp"
4 |
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/B.hpp:5:26: warning: function 'BFunc' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/B.hpp:5:26: note: mark the definition as 'inline'
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
| inline
Suppressed 134 warnings (134 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.
```
Same result with run-clang-tidy-21 :
```
test# run-clang-tidy-21 -header-filter=.* -p=build .
Enabled checks:
misc-confusable-identifiers
misc-const-correctness
misc-coroutine-hostile-raii
misc-definitions-in-headers
misc-header-include-cycle
misc-include-cleaner
misc-misleading-bidirectional
misc-misleading-identifier
misc-misplaced-const
misc-new-delete-overloads
misc-no-recursion
misc-non-copyable-objects
misc-non-private-member-variables-in-classes
misc-redundant-_expression_
misc-static-assert
misc-throw-by-value-catch-by-reference
misc-unconventional-assign-operator
misc-uniqueptr-reset-release
misc-unused-alias-decls
misc-unused-parameters
misc-unused-using-decls
misc-use-anonymous-namespace
misc-use-internal-linkage
Running clang-tidy for 1 files out of 1 in compilation database ...
[1/1][0.3s] clang-tidy-21 -header-filter=.* -p=build /workspace/build/test/main.cpp
/workspace/build/test/A.hpp:6:26: warning: function 'AFunc' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
6 | std::vector<std::string> AFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/A.hpp:6:26: note: mark the definition as 'inline'
6 | std::vector<std::string> AFunc() { return std::vector<std::string>(); }
| ^
| inline
/workspace/build/test/B.hpp:5:26: warning: function 'BFunc' defined in a header file; function definitions in header files can lead to ODR violations [misc-definitions-in-headers]
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
/workspace/build/test/B.hpp:5:26: note: mark the definition as 'inline'
5 | std::vector<std::string> BFunc() { return std::vector<std::string>(); }
| ^
| inline
136 warnings generated.
Suppressed 134 warnings (134 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.
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs