[clang-tools-extra] [clang-tidy][misc-include-cleaner]Avoid to insert same include header multiple times (PR #65431)
kadir çetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 6 00:27:49 PDT 2023
================
@@ -209,14 +213,17 @@ void IncludeCleanerCheck::check(const MatchFinder::MatchResult &Result) {
// main file.
if (auto Replacement =
HeaderIncludes.insert(llvm::StringRef{Spelling}.trim("\"<>"),
- Angled, tooling::IncludeDirective::Include))
- diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
- "no header providing \"%0\" is directly included")
- << Inc.SymRef.Target.name()
- << FixItHint::CreateInsertion(
- SM->getComposedLoc(SM->getMainFileID(),
- Replacement->getOffset()),
- Replacement->getReplacementText());
+ Angled, tooling::IncludeDirective::Include)) {
+ DiagnosticBuilder DB =
+ diag(SM->getSpellingLoc(Inc.SymRef.RefLocation),
+ "no header providing \"%0\" is directly included")
+ << Inc.SymRef.Target.name();
+ if (areDiagsSelfContained() ||
+ InsertedHeaders.insert(Replacement->getReplacementText()).second)
----------------
kadircet wrote:
nit: since we have multiple lines (despite being a single statement) can you wrap the body in `{}` ?
https://github.com/llvm/llvm-project/pull/65431
More information about the cfe-commits
mailing list