@@ -96,12 +96,11 @@ static QualType getReplacementCastType(const Expr *CondLhs, const Expr *CondRhs,
9696 return GlobalImplicitCastType;
9797}
9898
99- static std::string createReplacement (const Expr *CondLhs, const Expr *CondRhs,
100- const Expr *AssignLhs,
101- const SourceManager &Source,
102- const LangOptions &LO,
103- StringRef FunctionName,
104- const BinaryOperator *BO) {
99+ static std::string
100+ createReplacement (const Expr *CondLhs, const Expr *CondRhs,
101+ const Expr *AssignLhs, const SourceManager &Source,
102+ const LangOptions &LO, StringRef FunctionName,
103+ const BinaryOperator *BO, StringRef Comment = " " ) {
105104 const llvm::StringRef CondLhsStr = Lexer::getSourceText (
106105 Source.getExpansionRange (CondLhs->getSourceRange ()), Source, LO);
107106 const llvm::StringRef CondRhsStr = Lexer::getSourceText (
@@ -116,7 +115,7 @@ static std::string createReplacement(const Expr *CondLhs, const Expr *CondRhs,
116115 (!GlobalImplicitCastType.isNull ()
117116 ? " <" + GlobalImplicitCastType.getAsString () + " >("
118117 : " (" ) +
119- CondLhsStr + " , " + CondRhsStr + " );" )
118+ CondLhsStr + " , " + CondRhsStr + " );" + Comment )
120119 .str ();
121120}
122121
@@ -172,13 +171,21 @@ void UseStdMinMaxCheck::check(const MatchFinder::MatchResult &Result) {
172171
173172 auto ReplaceAndDiagnose = [&](const llvm::StringRef FunctionName) {
174173 const SourceManager &Source = *Result.SourceManager ;
174+ const std::string Comment =
175+ Lexer::getSourceText (
176+ CharSourceRange::getCharRange (
177+ Lexer::getLocForEndOfToken (If->getRParenLoc (), 0 , Source, LO),
178+ If->getThen ()->getBeginLoc ()),
179+ Source, LO)
180+ .rtrim ()
181+ .str ();
175182 diag (IfLocation, " use `%0` instead of `%1`" )
176183 << FunctionName << BinaryOp->getOpcodeStr ()
177184 << FixItHint::CreateReplacement (
178185 SourceRange (IfLocation, Lexer::getLocForEndOfToken (
179186 ThenLocation, 0 , Source, LO)),
180187 createReplacement (CondLhs, CondRhs, AssignLhs, Source, LO,
181- FunctionName, BinaryOp))
188+ FunctionName, BinaryOp, Comment ))
182189 << IncludeInserter.createIncludeInsertion (
183190 Source.getFileID (If->getBeginLoc ()), AlgorithmHeader);
184191 };
0 commit comments