[clang-tidy][NFC] Migrate away from make_* functions (#173191)

These seem to always have a better alternative (CTAD, braced init-list,
etc.)
This commit is contained in:
Victor Chernyakin 2025-12-21 13:50:46 -06:00 committed by GitHub
parent e644f06c2f
commit e69deb236e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 33 additions and 36 deletions

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}

View File

@ -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;

View File

@ -60,7 +60,7 @@ static std::pair<std::size_t, bool> countCaseLabels(const SwitchStmt *Switch) {
CurrentCase = CurrentCase->getNextSwitchCase();
}
return std::make_pair(CaseCount, HasDefault);
return {CaseCount, HasDefault};
}
/// This function calculate 2 ** Bits and returns

View File

@ -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.

View File

@ -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<StmtAncestorASTVisitor>::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<VarDecl>(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) {

View File

@ -118,7 +118,7 @@ struct CognitiveComplexity final {
} else
llvm_unreachable("should not get to here.");
return std::make_pair(MsgId, Increment);
return {MsgId, Increment};
}
};

View File

@ -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.

View File

@ -521,17 +521,15 @@ SuspiciousCallArgumentCheck::SuspiciousCallArgumentCheck(
auto H = static_cast<Heuristic>(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());
}
}

View File

@ -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.
});

View File

@ -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,

View File

@ -35,7 +35,7 @@ std::optional<FixItHint> 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(