From e69deb236eb464f56c8229c3c190ca686e4284b6 Mon Sep 17 00:00:00 2001 From: Victor Chernyakin Date: Sun, 21 Dec 2025 13:50:46 -0600 Subject: [PATCH] [clang-tidy][NFC] Migrate away from `make_*` functions (#173191) These seem to always have a better alternative (CTAD, braced init-list, etc.) --- clang-tools-extra/clang-tidy/ClangTidy.cpp | 2 +- .../ClangTidyDiagnosticConsumer.cpp | 6 +++--- .../abseil/DurationFactoryScaleCheck.cpp | 20 +++++++++---------- .../bugprone/VirtualNearMissCheck.cpp | 2 +- .../hicpp/MultiwayPathsCoveredCheck.cpp | 2 +- .../clang-tidy/modernize/LoopConvertCheck.cpp | 7 +++---- .../clang-tidy/modernize/LoopConvertUtils.cpp | 6 +++--- .../FunctionCognitiveComplexityCheck.cpp | 2 +- .../readability/NamedParameterCheck.cpp | 2 +- .../SuspiciousCallArgumentCheck.cpp | 12 +++++------ .../utils/DesignatedInitializers.cpp | 2 +- .../clang-tidy/utils/HeaderGuard.cpp | 4 ++-- .../clang-tidy/utils/UsingInserter.cpp | 2 +- 13 files changed, 33 insertions(+), 36 deletions(-) diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp index 970c463029ab..e52794feedd2 100644 --- a/clang-tools-extra/clang-tidy/ClangTidy.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp @@ -176,7 +176,7 @@ public: ++AppliedFixes; } FixLoc = getLocation(FixAbsoluteFilePath, Repl.getOffset()); - FixLocations.push_back(std::make_pair(FixLoc, CanBeApplied)); + FixLocations.emplace_back(FixLoc, CanBeApplied); Entry.BuildDir = Error.BuildDirectory; } } diff --git a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp index faa568e521f7..0355eccc397e 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp @@ -659,13 +659,13 @@ void ClangTidyDiagnosticConsumer::removeIncompatibleErrors() { // disallowing the first one. switch (Type) { case ET_Begin: - Priority = std::make_tuple(Begin, Type, -End, -ErrorSize, ErrorId); + Priority = {Begin, Type, -End, -ErrorSize, ErrorId}; break; case ET_Insert: - Priority = std::make_tuple(Begin, Type, -End, ErrorSize, ErrorId); + Priority = {Begin, Type, -End, ErrorSize, ErrorId}; break; case ET_End: - Priority = std::make_tuple(End, Type, -Begin, ErrorSize, ErrorId); + Priority = {End, Type, -Begin, ErrorSize, ErrorId}; break; } } diff --git a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp index 9e403fb8be3d..b29fd3a0b94e 100644 --- a/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp +++ b/clang-tools-extra/clang-tidy/abseil/DurationFactoryScaleCheck.cpp @@ -51,40 +51,40 @@ getNewScaleSingleStep(DurationScale OldScale, double Multiplier) { switch (OldScale) { case DurationScale::Hours: if (Multiplier <= 1.0 / 60.0) - return std::make_tuple(DurationScale::Minutes, Multiplier * 60.0); + return {{DurationScale::Minutes, Multiplier * 60.0}}; break; case DurationScale::Minutes: if (Multiplier >= 60.0) - return std::make_tuple(DurationScale::Hours, Multiplier / 60.0); + return {{DurationScale::Hours, Multiplier / 60.0}}; if (Multiplier <= 1.0 / 60.0) - return std::make_tuple(DurationScale::Seconds, Multiplier * 60.0); + return {{DurationScale::Seconds, Multiplier * 60.0}}; break; case DurationScale::Seconds: if (Multiplier >= 60.0) - return std::make_tuple(DurationScale::Minutes, Multiplier / 60.0); + return {{DurationScale::Minutes, Multiplier / 60.0}}; if (Multiplier <= 1e-3) - return std::make_tuple(DurationScale::Milliseconds, Multiplier * 1e3); + return {{DurationScale::Milliseconds, Multiplier * 1e3}}; break; case DurationScale::Milliseconds: if (Multiplier >= 1e3) - return std::make_tuple(DurationScale::Seconds, Multiplier / 1e3); + return {{DurationScale::Seconds, Multiplier / 1e3}}; if (Multiplier <= 1e-3) - return std::make_tuple(DurationScale::Microseconds, Multiplier * 1e3); + return {{DurationScale::Microseconds, Multiplier * 1e3}}; break; case DurationScale::Microseconds: if (Multiplier >= 1e3) - return std::make_tuple(DurationScale::Milliseconds, Multiplier / 1e3); + return {{DurationScale::Milliseconds, Multiplier / 1e3}}; if (Multiplier <= 1e-3) - return std::make_tuple(DurationScale::Nanoseconds, Multiplier * 1e-3); + return {{DurationScale::Nanoseconds, Multiplier * 1e-3}}; break; case DurationScale::Nanoseconds: if (Multiplier >= 1e3) - return std::make_tuple(DurationScale::Microseconds, Multiplier / 1e3); + return {{DurationScale::Microseconds, Multiplier / 1e3}}; break; } diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp index 830913a8c237..0fd965f88e0d 100644 --- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp @@ -192,7 +192,7 @@ bool VirtualNearMissCheck::isPossibleToBeOverridden( bool VirtualNearMissCheck::isOverriddenByDerivedClass( const CXXMethodDecl *BaseMD, const CXXRecordDecl *DerivedRD) { - auto Key = std::make_pair(BaseMD, DerivedRD); + const std::pair Key(BaseMD, DerivedRD); auto Iter = OverriddenMap.find(Key); if (Iter != OverriddenMap.end()) return Iter->second; diff --git a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp index e9a5819a939f..18d5aa44a6a9 100644 --- a/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp +++ b/clang-tools-extra/clang-tidy/hicpp/MultiwayPathsCoveredCheck.cpp @@ -60,7 +60,7 @@ static std::pair countCaseLabels(const SwitchStmt *Switch) { CurrentCase = CurrentCase->getNextSwitchCase(); } - return std::make_pair(CaseCount, HasDefault); + return {CaseCount, HasDefault}; } /// This function calculate 2 ** Bits and returns diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp index fcac40067a6a..7343557ccb72 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp @@ -424,7 +424,7 @@ getContainerFromBeginEndCall(const Expr *Init, bool IsBegin, bool *IsArrow, return {}; if (!Call->Name.empty() && Call->Name != "c") return {}; - return std::make_pair(Call->Container, Call->CallKind); + return {Call->Container, Call->CallKind}; } /// Determines the container whose begin() and end() functions are called @@ -734,7 +734,7 @@ void LoopConvertCheck::doConversion( ? "&" + VarNameOrStructuredBinding : VarNameOrStructuredBinding; } - TUInfo->getReplacedVars().insert(std::make_pair(Loop, IndexVar)); + TUInfo->getReplacedVars().try_emplace(Loop, IndexVar); FixIts.push_back(FixItHint::CreateReplacement( CharSourceRange::getTokenRange(Range), ReplaceText)); } @@ -796,8 +796,7 @@ void LoopConvertCheck::doConversion( FixIts.push_back(*Insertion); } diag(Loop->getForLoc(), "use range-based for loop instead") << FixIts; - TUInfo->getGeneratedDecls().insert( - make_pair(Loop, VarNameOrStructuredBinding)); + TUInfo->getGeneratedDecls().try_emplace(Loop, VarNameOrStructuredBinding); } /// Returns a string which refers to the container iterated over. diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp index e6392ccc8ac3..c899018ba439 100644 --- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp +++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp @@ -35,7 +35,7 @@ namespace clang::tidy::modernize { /// the stack is the parent of the current statement (NULL for the topmost /// statement). bool StmtAncestorASTVisitor::TraverseStmt(Stmt *Statement) { - StmtAncestors.insert(std::make_pair(Statement, StmtStack.back())); + StmtAncestors.try_emplace(Statement, StmtStack.back()); StmtStack.push_back(Statement); RecursiveASTVisitor::TraverseStmt(Statement); StmtStack.pop_back(); @@ -50,7 +50,7 @@ bool StmtAncestorASTVisitor::TraverseStmt(Stmt *Statement) { bool StmtAncestorASTVisitor::VisitDeclStmt(DeclStmt *Statement) { for (const auto *Decl : Statement->decls()) if (const auto *V = dyn_cast(Decl)) - DeclParents.insert(std::make_pair(V, Statement)); + DeclParents.try_emplace(V, Statement); return true; } @@ -469,7 +469,7 @@ void ForLoopIndexUseVisitor::addComponent(const Expr *E) { llvm::FoldingSetNodeID ID; const Expr *Node = E->IgnoreParenImpCasts(); Node->Profile(ID, *Context, true); - DependentExprs.push_back(std::make_pair(Node, ID)); + DependentExprs.emplace_back(Node, ID); } void ForLoopIndexUseVisitor::addUsage(const Usage &U) { diff --git a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp index f1216e0a39f0..43b98faaf614 100644 --- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp @@ -118,7 +118,7 @@ struct CognitiveComplexity final { } else llvm_unreachable("should not get to here."); - return std::make_pair(MsgId, Increment); + return {MsgId, Increment}; } }; diff --git a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp index 1283632a91bb..46f11027c970 100644 --- a/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/NamedParameterCheck.cpp @@ -83,7 +83,7 @@ void NamedParameterCheck::check(const MatchFinder::MatchResult &Result) { if (Data.contains("/*")) continue; - UnnamedParams.push_back(std::make_pair(Function, I)); + UnnamedParams.emplace_back(Function, I); } // Emit only one warning per function but fixits for all unnamed parameters. diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp index 8fa20e224833..e1a73aa47919 100644 --- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp @@ -521,17 +521,15 @@ SuspiciousCallArgumentCheck::SuspiciousCallArgumentCheck( auto H = static_cast(Idx); if (GetToggleOpt(H)) AppliedHeuristics.emplace_back(H); - ConfiguredBounds.emplace_back( - std::make_pair(GetBoundOpt(H, BoundKind::DissimilarBelow), - GetBoundOpt(H, BoundKind::SimilarAbove))); + ConfiguredBounds.emplace_back(GetBoundOpt(H, BoundKind::DissimilarBelow), + GetBoundOpt(H, BoundKind::SimilarAbove)); } for (const StringRef Abbreviation : optutils::parseStringList( Options.get("Abbreviations", DefaultAbbreviations))) { - auto KeyAndValue = Abbreviation.split("="); - assert(!KeyAndValue.first.empty() && !KeyAndValue.second.empty()); - AbbreviationDictionary.insert( - std::make_pair(KeyAndValue.first, KeyAndValue.second.str())); + const auto [Key, Value] = Abbreviation.split("="); + assert(!Key.empty() && !Value.empty()); + AbbreviationDictionary.try_emplace(Key, Value.str()); } } diff --git a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp index b068ae24a391..e22ae8a5095b 100644 --- a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp +++ b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp @@ -142,7 +142,7 @@ static void collectDesignators( if (!Fields) return; for (const Expr *Init : Sem->inits()) { - auto Next = llvm::make_scope_exit([&, Size(Prefix.size())] { + const llvm::scope_exit Next([&, Size(Prefix.size())] { Fields.next(); // Always advance to the next subobject name. Prefix.resize(Size); // Erase any designator we appended. }); diff --git a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp index d36b187b1da1..59cae8870837 100644 --- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp +++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp @@ -48,8 +48,8 @@ public: return; // Record #ifndefs that succeeded. We also need the Location of the Name. - Ifndefs[MacroNameTok.getIdentifierInfo()] = - std::make_pair(Loc, MacroNameTok.getLocation()); + Ifndefs[MacroNameTok.getIdentifierInfo()] = {Loc, + MacroNameTok.getLocation()}; } void MacroDefined(const Token &MacroNameTok, diff --git a/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp b/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp index 6a591c1a84a4..2040f4223111 100644 --- a/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp +++ b/clang-tools-extra/clang-tidy/utils/UsingInserter.cpp @@ -35,7 +35,7 @@ std::optional UsingInserter::createUsingDeclaration( if (!Function) return std::nullopt; - if (AddedUsing.count(std::make_pair(Function, QualifiedName.str())) != 0) + if (AddedUsing.count({Function, QualifiedName.str()}) != 0) return std::nullopt; const SourceLocation InsertLoc = Lexer::getLocForEndOfToken(