llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
27.57k stars 11.32k forks source link

clang-include-cleaner - replaces chrono with bits/chrono #68213

Open PiotrZSL opened 10 months ago

PiotrZSL commented 10 months ago

Issues found:

a)

+#include <bits/basic_string.h>
+#include <string>

b)

-#include <chrono>
+#include <bits/chrono.h>

Tested version from LLVM 17.0.2

misc-include-cleaner provide more information:

160   - DiagnosticName:  misc-include-cleaner
161     DiagnosticMessage:
162       Message:         'no header providing "std::operator""s" is directly included'
163       FilePath:        'some-file.cpp'
164       FileOffset:      982
165       Replacements:
166         - FilePath:        'some-file.cpp'
167           Offset:          52
168           Length:          0
169           ReplacementText: "#include <bits/basic_string.h>\n"

And:

304   - DiagnosticName:  misc-include-cleaner
305     DiagnosticMessage:
306       Message:         'no header providing "std::chrono::ceil" is directly included'
307       FilePath:        'some-file.cpp'
308       FileOffset:      3133
309       Replacements:
310         - FilePath:        'some-file.cpp'
311           Offset:          43
312           Length:          0
313           ReplacementText: "#include <bits/chrono.h>\n"

When <chrono> is already included.

llvmbot commented 10 months ago

@llvm/issue-subscribers-clang-include-cleaner

Issues found: a) ``` +#include <bits/basic_string.h> +#include <string> ``` b) ``` -#include <chrono> +#include <bits/chrono.h> ``` Tested version from LLVM 17.0.2 misc-include-cleaner provide more information: ``` 160 - DiagnosticName: misc-include-cleaner 161 DiagnosticMessage: 162 Message: 'no header providing "std::operator""s" is directly included' 163 FilePath: 'some-file.cpp' 164 FileOffset: 982 165 Replacements: 166 - FilePath: 'some-file.cpp' 167 Offset: 52 168 Length: 0 169 ReplacementText: "#include <bits/basic_string.h>\n" ``` And: ``` 304 - DiagnosticName: misc-include-cleaner 305 DiagnosticMessage: 306 Message: 'no header providing "std::chrono::ceil" is directly included' 307 FilePath: 'some-file.cpp' 308 FileOffset: 3133 309 Replacements: 310 - FilePath: 'some-file.cpp' 311 Offset: 43 312 Length: 0 313 ReplacementText: "#include <bits/chrono.h>\n" ``` When `<chrono>` is already included.
ZedThree commented 9 months ago

I've just bumped into this with std::string_literals::operator""s, I get a warning that

no header providing "std::operator""s" is directly included

which can only be silenced by including bits/basic_string.h. It would be nice to teach misc-include-cleaner about these implementation details.

Here's a minimal reproducer on Compiler Explorer:

https://godbolt.org/z/r9Tzrs4nx