Skip to content

Commit f2e8474

Browse files
committed
Squash: Apply Clang format fixes and ensure InnerCall uses std::min or std::max in replacement generation
1 parent 1bed756 commit f2e8474

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

clang-tools-extra/clang-tidy/modernize/MinMaxUseInitializerListCheck.cpp

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ MinMaxUseInitializerListCheck::findArgs(const MatchFinder::MatchResult &Match,
8989
Result.Compare = nullptr;
9090

9191
if (Call->getNumArgs() > 2) {
92-
auto argIterator = Call->arguments().begin();
93-
std::advance(argIterator, 2);
94-
Result.Compare = *argIterator;
92+
auto ArgIterator = Call->arguments().begin();
93+
std::advance(ArgIterator, 2);
94+
Result.Compare = *ArgIterator;
9595
}
9696

9797
for (const Expr *Arg : Call->arguments()) {
@@ -153,15 +153,20 @@ std::string MinMaxUseInitializerListCheck::generateReplacement(
153153
for (const Expr *Arg : Result.Args) {
154154
QualType ArgType = Arg->getType();
155155

156-
// check if expression is std::min or std::max
157156
if (const auto *InnerCall = dyn_cast<CallExpr>(Arg)) {
158-
if (InnerCall->getDirectCallee() &&
159-
InnerCall->getDirectCallee()->getNameAsString() !=
160-
TopCall->getDirectCallee()->getNameAsString()) {
161-
FindArgsResult innerResult = findArgs(Match, InnerCall);
162-
ReplacementText += generateReplacement(Match, InnerCall, innerResult) +=
163-
"})";
164-
continue;
157+
if (InnerCall->getDirectCallee()) {
158+
std::string InnerCallNameStr =
159+
InnerCall->getDirectCallee()->getQualifiedNameAsString();
160+
161+
if (InnerCallNameStr !=
162+
TopCall->getDirectCallee()->getQualifiedNameAsString() &&
163+
(InnerCallNameStr == "std::min" ||
164+
InnerCallNameStr == "std::max")) {
165+
FindArgsResult innerResult = findArgs(Match, InnerCall);
166+
ReplacementText +=
167+
generateReplacement(Match, InnerCall, innerResult) + ", ";
168+
continue;
169+
}
165170
}
166171
}
167172

0 commit comments

Comments
 (0)