-
Notifications
You must be signed in to change notification settings - Fork 15.6k
[clang-tidy][NFC] Migrate away from make_* functions
#173191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
localspook
wants to merge
2
commits into
llvm:main
Choose a base branch
from
localspook:no-make-functions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
|
@llvm/pr-subscribers-clang-tools-extra @llvm/pr-subscribers-clang-tidy Author: Victor Chernyakin (localspook) ChangesFull diff: https://github.com/llvm/llvm-project/pull/173191.diff 13 Files Affected:
diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 0893884f937d3..bd09031f0c8ea 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -178,7 +178,7 @@ class ErrorReporter {
++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 16a4d13b9aadb..af70ed7c5665f 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 9e403fb8be3dd..b29fd3a0b94ee 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 0d69b9fd88213..3e122b7e35f67 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -194,7 +194,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 e9a5819a939f9..18d5aa44a6a95 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<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
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index ce01a85f70fde..24eb6a67b0996 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -420,7 +420,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
@@ -731,7 +731,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));
}
@@ -793,8 +793,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 f6685dda7e09e..4843a7ab925cb 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<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;
}
@@ -470,7 +470,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 a966f1f6e24c5..7b0651a328b27 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.cpp
@@ -116,7 +116,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 1283632a91bb1..46f11027c970e 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 0b52a9664a7a5..c7ab1d283db3e 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<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());
}
}
diff --git a/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp b/clang-tools-extra/clang-tidy/utils/DesignatedInitializers.cpp
index b068ae24a391b..e22ae8a5095be 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 d36b187b1da14..59cae88708377 100644
--- a/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
+++ b/clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
@@ -48,8 +48,8 @@ class HeaderGuardPPCallbacks : public PPCallbacks {
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 6a591c1a84a47..2040f42231118 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<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(
|
make_* functions to CTADmake_* functions
localspook
commented
Dec 21, 2025
| case DurationScale::Hours: | ||
| if (Multiplier <= 1.0 / 60.0) | ||
| return std::make_tuple(DurationScale::Minutes, Multiplier * 60.0); | ||
| return {{DurationScale::Minutes, Multiplier * 60.0}}; |
Contributor
Author
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The double braces are needed because this function returns std::optional<std::tuple<...>>
make_* functionsmake_* functions
EugeneZelenko
approved these changes
Dec 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These seem to always have a better alternative (CTAD, braced init-list, etc.)