diff --git a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp --- a/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp +++ b/clang-tools-extra/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp @@ -135,12 +135,11 @@ if (auto Entry = SM.getFileManager().getFile(R.getFilePath())) { if (SourceTU) { auto &Replaces = DiagReplacements[*Entry]; - auto It = Replaces.find(R); - if (It == Replaces.end()) - Replaces.emplace(R, SourceTU); - else if (It->second != SourceTU) - // This replacement is a duplicate of one suggested by another TU. + auto InsertPos = Replaces.try_emplace(R, SourceTU); + // This replacement is a duplicate of one suggested by another TU. + if (!InsertPos.second && InsertPos.first->second != SourceTU) { return; + } } GroupedReplacements[*Entry].push_back(R); } else if (Warned.insert(R.getFilePath()).second) {