Skip to content

Commit 7832be9

Browse files
committed
move replacement string creation out of loop
1 parent 28afda5 commit 7832be9

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,7 @@ void UseConstexprCheck::check(const MatchFinder::MatchResult &Result) {
898898
}
899899

900900
void UseConstexprCheck::onEndOfTranslationUnit() {
901+
const std::string FunctionReplacement = ConstexprString + " ";
901902
for (const FunctionDecl *Func : Functions) {
902903
const SourceRange R =
903904
SourceRange(Func->getInnerLocStart(), Func->getLocation());
@@ -908,8 +909,9 @@ void UseConstexprCheck::onEndOfTranslationUnit() {
908909
for (const Decl *D : Func->redecls())
909910
if (const auto *FDecl = llvm::dyn_cast<FunctionDecl>(D))
910911
Diag << FixItHint::CreateInsertion(FDecl->getInnerLocStart(),
911-
ConstexprString + " ");
912+
FunctionReplacement);
912913
}
914+
const std::string VariableReplacement = ConstexprString + " ";
913915
for (const auto &[Var, FuncCtx] : VariableMapping) {
914916
if (FuncCtx && getLangOpts().CPlusPlus23 && Var->isStaticLocal() &&
915917
Functions.contains(FuncCtx))
@@ -920,11 +922,11 @@ void UseConstexprCheck::onEndOfTranslationUnit() {
920922
diag(Var->getLocation(), "variable %0 can be declared 'constexpr'")
921923
<< Var << R
922924
<< FixItHint::CreateInsertion(Var->getInnerLocStart(),
923-
ConstexprString + " ");
925+
VariableReplacement);
924926
// Since either of the locs can be in a macro, use `makeFileCharRange` to be
925927
// sure that we have a consistent `CharSourceRange`, located entirely in the
926928
// source file.
927-
CharSourceRange FileRange = Lexer::makeFileCharRange(
929+
const CharSourceRange FileRange = Lexer::makeFileCharRange(
928930
CharSourceRange::getCharRange(Var->getInnerLocStart(),
929931
Var->getLocation()),
930932
Var->getASTContext().getSourceManager(), getLangOpts());

0 commit comments

Comments
 (0)