[clang-tools-extra] 385dbc1 - [clang-tidy][NFC] Fix misc-const-correctness warnings (12/N) (#167129)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 8 08:05:40 PST 2025
Author: Baranov Victor
Date: 2025-11-08T19:05:36+03:00
New Revision: 385dbc12c4597a158e1c7906e39a4832c4de97cc
URL: https://github.com/llvm/llvm-project/commit/385dbc12c4597a158e1c7906e39a4832c4de97cc
DIFF: https://github.com/llvm/llvm-project/commit/385dbc12c4597a158e1c7906e39a4832c4de97cc.diff
LOG: [clang-tidy][NFC] Fix misc-const-correctness warnings (12/N) (#167129)
Added:
Modified:
clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
index c0a778a027377..ed30d01e645d1 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ArgumentCommentCheck.cpp
@@ -81,14 +81,16 @@ static std::vector<std::pair<SourceLocation, StringRef>>
getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
std::vector<std::pair<SourceLocation, StringRef>> Comments;
auto &SM = Ctx->getSourceManager();
- std::pair<FileID, unsigned> BeginLoc = SM.getDecomposedLoc(Range.getBegin()),
- EndLoc = SM.getDecomposedLoc(Range.getEnd());
+ const std::pair<FileID, unsigned> BeginLoc =
+ SM.getDecomposedLoc(Range.getBegin()),
+ EndLoc =
+ SM.getDecomposedLoc(Range.getEnd());
if (BeginLoc.first != EndLoc.first)
return Comments;
bool Invalid = false;
- StringRef Buffer = SM.getBufferData(BeginLoc.first, &Invalid);
+ const StringRef Buffer = SM.getBufferData(BeginLoc.first, &Invalid);
if (Invalid)
return Comments;
@@ -106,7 +108,7 @@ getCommentsInRange(ASTContext *Ctx, CharSourceRange Range) {
break;
if (Tok.is(tok::comment)) {
- std::pair<FileID, unsigned> CommentLoc =
+ const std::pair<FileID, unsigned> CommentLoc =
SM.getDecomposedLoc(Tok.getLocation());
assert(CommentLoc.first == BeginLoc.first);
Comments.emplace_back(
@@ -125,7 +127,7 @@ static std::vector<std::pair<SourceLocation, StringRef>>
getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
std::vector<std::pair<SourceLocation, StringRef>> Comments;
while (Loc.isValid()) {
- clang::Token Tok = utils::lexer::getPreviousToken(
+ const clang::Token Tok = utils::lexer::getPreviousToken(
Loc, Ctx->getSourceManager(), Ctx->getLangOpts(),
/*SkipComments=*/false);
if (Tok.isNot(tok::comment))
@@ -142,11 +144,11 @@ getCommentsBeforeLoc(ASTContext *Ctx, SourceLocation Loc) {
static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
StringRef ArgName, unsigned ArgIndex) {
- std::string ArgNameLowerStr = ArgName.lower();
- StringRef ArgNameLower = ArgNameLowerStr;
+ const std::string ArgNameLowerStr = ArgName.lower();
+ const StringRef ArgNameLower = ArgNameLowerStr;
// The threshold is arbitrary.
- unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
- unsigned ThisED = ArgNameLower.edit_distance(
+ const unsigned UpperBound = ((ArgName.size() + 2) / 3) + 1;
+ const unsigned ThisED = ArgNameLower.edit_distance(
Params[ArgIndex]->getIdentifier()->getName().lower(),
/*AllowReplacements=*/true, UpperBound);
if (ThisED >= UpperBound)
@@ -155,7 +157,7 @@ static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
for (unsigned I = 0, E = Params.size(); I != E; ++I) {
if (I == ArgIndex)
continue;
- IdentifierInfo *II = Params[I]->getIdentifier();
+ const IdentifierInfo *II = Params[I]->getIdentifier();
if (!II)
continue;
@@ -163,9 +165,9 @@ static bool isLikelyTypo(llvm::ArrayRef<ParmVarDecl *> Params,
// Other parameters must be an edit distance at least Threshold more away
// from this parameter. This gives us greater confidence that this is a
// typo of this parameter and not one with a similar name.
- unsigned OtherED = ArgNameLower.edit_distance(II->getName().lower(),
- /*AllowReplacements=*/true,
- ThisED + Threshold);
+ const unsigned OtherED = ArgNameLower.edit_distance(
+ II->getName().lower(),
+ /*AllowReplacements=*/true, ThisED + Threshold);
if (OtherED < ThisED + Threshold)
return false;
}
@@ -267,7 +269,8 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
return;
Callee = Callee->getFirstDecl();
- unsigned NumArgs = std::min<unsigned>(Args.size(), Callee->getNumParams());
+ const unsigned NumArgs =
+ std::min<unsigned>(Args.size(), Callee->getNumParams());
if ((NumArgs == 0) || (IgnoreSingleArgument && NumArgs == 1))
return;
@@ -279,7 +282,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
for (unsigned I = 0; I < NumArgs; ++I) {
const ParmVarDecl *PVD = Callee->getParamDecl(I);
- IdentifierInfo *II = PVD->getIdentifier();
+ const IdentifierInfo *II = PVD->getIdentifier();
if (!II)
continue;
if (FunctionDecl *Template = Callee->getTemplateInstantiationPattern()) {
@@ -293,7 +296,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
}
}
- CharSourceRange BeforeArgument =
+ const CharSourceRange BeforeArgument =
MakeFileCharRange(ArgBeginLoc, Args[I]->getBeginLoc());
ArgBeginLoc = Args[I]->getEndLoc();
@@ -302,7 +305,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
Comments = getCommentsInRange(Ctx, BeforeArgument);
} else {
// Fall back to parsing back from the start of the argument.
- CharSourceRange ArgsRange =
+ const CharSourceRange ArgsRange =
MakeFileCharRange(Args[I]->getBeginLoc(), Args[I]->getEndLoc());
Comments = getCommentsBeforeLoc(Ctx, ArgsRange.getBegin());
}
@@ -312,7 +315,7 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
if (IdentRE.match(Comment.second, &Matches) &&
!sameName(Matches[2], II->getName(), StrictMode)) {
{
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Comment.first, "argument name '%0' in comment does not "
"match parameter name %1")
<< Matches[2] << II;
@@ -332,9 +335,9 @@ void ArgumentCommentCheck::checkCallArgs(ASTContext *Ctx,
// If the argument comments are missing for literals add them.
if (Comments.empty() && shouldAddComment(Args[I])) {
- std::string ArgComment =
+ const std::string ArgComment =
(llvm::Twine("/*") + II->getName() + "=*/").str();
- DiagnosticBuilder Diag =
+ const DiagnosticBuilder Diag =
diag(Args[I]->getBeginLoc(),
"argument comment missing for literal argument %0")
<< II
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
index 170050247014a..a29aa552b0953 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssertSideEffectCheck.cpp
@@ -29,7 +29,7 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
const Expr *E = &Node;
if (const auto *Op = dyn_cast<UnaryOperator>(E)) {
- UnaryOperator::Opcode OC = Op->getOpcode();
+ const UnaryOperator::Opcode OC = Op->getOpcode();
return OC == UO_PostInc || OC == UO_PostDec || OC == UO_PreInc ||
OC == UO_PreDec;
}
@@ -44,7 +44,7 @@ AST_MATCHER_P2(Expr, hasSideEffect, bool, CheckFunctionCalls,
if (MethodDecl->isConst())
return false;
- OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
+ const OverloadedOperatorKind OpKind = OpCallExpr->getOperator();
return OpKind == OO_Equal || OpKind == OO_PlusEqual ||
OpKind == OO_MinusEqual || OpKind == OO_StarEqual ||
OpKind == OO_SlashEqual || OpKind == OO_AmpEqual ||
@@ -130,7 +130,7 @@ void AssertSideEffectCheck::check(const MatchFinder::MatchResult &Result) {
StringRef AssertMacroName;
while (Loc.isValid() && Loc.isMacroID()) {
- StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
+ const StringRef MacroName = Lexer::getImmediateMacroName(Loc, SM, LangOpts);
Loc = SM.getImmediateMacroCallerLoc(Loc);
// Check if this macro is an assert.
diff --git a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
index 2c8856298e7be..d5d8a29d96969 100644
--- a/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/AssignmentInIfConditionCheck.cpp
@@ -66,7 +66,7 @@ void AssignmentInIfConditionCheck::check(
}
void AssignmentInIfConditionCheck::report(const Expr *AssignmentExpr) {
- SourceLocation OpLoc =
+ const SourceLocation OpLoc =
isa<BinaryOperator>(AssignmentExpr)
? cast<BinaryOperator>(AssignmentExpr)->getOperatorLoc()
: cast<CXXOperatorCallExpr>(AssignmentExpr)->getOperatorLoc();
diff --git a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
index e1d0538ab1644..3e1188d5e2463 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BadSignalToKillThreadCheck.cpp
@@ -40,7 +40,7 @@ void BadSignalToKillThreadCheck::check(const MatchFinder::MatchResult &Result) {
const Token &T = MI->tokens().back();
if (!T.isLiteral() || !T.getLiteralData())
return std::nullopt;
- StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
+ const StringRef ValueStr = StringRef(T.getLiteralData(), T.getLength());
llvm::APInt IntValue;
constexpr unsigned AutoSenseRadix = 0;
diff --git a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
index 07bb08166a006..8e0f0c55bdf94 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BranchCloneCheck.cpp
@@ -281,8 +281,8 @@ static bool isIdenticalStmt(const ASTContext &Ctx, const Stmt *Stmt1,
const auto *IntLit1 = cast<IntegerLiteral>(Stmt1);
const auto *IntLit2 = cast<IntegerLiteral>(Stmt2);
- llvm::APInt I1 = IntLit1->getValue();
- llvm::APInt I2 = IntLit2->getValue();
+ const llvm::APInt I1 = IntLit1->getValue();
+ const llvm::APInt I2 = IntLit2->getValue();
if (I1.getBitWidth() != I2.getBitWidth())
return false;
return I1 == I2;
@@ -352,7 +352,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
}
}
- size_t N = Branches.size();
+ const size_t N = Branches.size();
llvm::BitVector KnownAsClone(N);
for (size_t I = 0; I + 1 < N; I++) {
@@ -375,7 +375,7 @@ void BranchCloneCheck::check(const MatchFinder::MatchResult &Result) {
// We report the first occurrence only when we find the second one.
diag(Branches[I]->getBeginLoc(),
"repeated branch body in conditional chain");
- SourceLocation End =
+ const SourceLocation End =
Lexer::getLocForEndOfToken(Branches[I]->getEndLoc(), 0,
*Result.SourceManager, getLangOpts());
if (End.isValid()) {
diff --git a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
index 76bcbbbcdf680..ccbc86ae74cc6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CopyConstructorInitCheck.cpp
@@ -31,7 +31,7 @@ void CopyConstructorInitCheck::registerMatchers(MatchFinder *Finder) {
void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
const auto *Ctor = Result.Nodes.getNodeAs<CXXConstructorDecl>("ctor");
- std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
+ const std::string ParamName = Ctor->getParamDecl(0)->getNameAsString();
// We want only one warning (and FixIt) for each ctor.
std::string FixItInitList;
@@ -40,7 +40,7 @@ void CopyConstructorInitCheck::check(const MatchFinder::MatchResult &Result) {
bool HasWrittenInitializer = false;
SmallVector<FixItHint, 2> SafeFixIts;
for (const auto *Init : Ctor->inits()) {
- bool CtorInitIsWritten = Init->isWritten();
+ const bool CtorInitIsWritten = Init->isWritten();
HasWrittenInitializer = HasWrittenInitializer || CtorInitIsWritten;
if (!Init->isBaseInitializer())
continue;
diff --git a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
index 60f7be8996933..5ef72eac763e7 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/CrtpConstructorAccessibilityCheck.cpp
@@ -116,9 +116,10 @@ void CrtpConstructorAccessibilityCheck::check(
assert(DerivedTemplateParameter &&
"No template parameter corresponds to the derived class of the CRTP.");
- bool NeedsFriend = !isDerivedParameterBefriended(CRTPDeclaration,
- DerivedTemplateParameter) &&
- !isDerivedClassBefriended(CRTPDeclaration, DerivedRecord);
+ const bool NeedsFriend =
+ !isDerivedParameterBefriended(CRTPDeclaration,
+ DerivedTemplateParameter) &&
+ !isDerivedClassBefriended(CRTPDeclaration, DerivedRecord);
const FixItHint HintFriend = FixItHint::CreateInsertion(
CRTPDeclaration->getBraceRange().getEnd(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
index 0aafdfd202390..cb4f69ae96115 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DefaultOperatorNewOnOveralignedTypeCheck.cpp
@@ -26,7 +26,7 @@ void DefaultOperatorNewOnOveralignedTypeCheck::check(
// Get the found 'new' expression.
const auto *NewExpr = Result.Nodes.getNodeAs<CXXNewExpr>("new");
- QualType T = NewExpr->getAllocatedType();
+ const QualType T = NewExpr->getAllocatedType();
// Dependent types do not have fixed alignment.
if (T->isDependentType())
return;
@@ -35,25 +35,25 @@ void DefaultOperatorNewOnOveralignedTypeCheck::check(
if (!D || !D->isCompleteDefinition())
return;
- ASTContext &Context = D->getASTContext();
+ const ASTContext &Context = D->getASTContext();
// Check if no alignment was specified for the type.
if (!Context.isAlignmentRequired(T))
return;
// The user-specified alignment (in bits).
- unsigned SpecifiedAlignment = D->getMaxAlignment();
+ const unsigned SpecifiedAlignment = D->getMaxAlignment();
// Double-check if no alignment was specified.
if (!SpecifiedAlignment)
return;
// The alignment used by default 'operator new' (in bits).
- unsigned DefaultNewAlignment = Context.getTargetInfo().getNewAlign();
+ const unsigned DefaultNewAlignment = Context.getTargetInfo().getNewAlign();
- bool OverAligned = SpecifiedAlignment > DefaultNewAlignment;
- bool HasDefaultOperatorNew =
+ const bool OverAligned = SpecifiedAlignment > DefaultNewAlignment;
+ const bool HasDefaultOperatorNew =
!NewExpr->getOperatorNew() || NewExpr->getOperatorNew()->isImplicit();
- unsigned CharWidth = Context.getTargetInfo().getCharWidth();
+ const unsigned CharWidth = Context.getTargetInfo().getCharWidth();
if (HasDefaultOperatorNew && OverAligned)
diag(NewExpr->getBeginLoc(),
"allocation function returns a pointer with alignment %0 but the "
diff --git a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
index 743e6cd27509b..7c5867619cf4e 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DerivedMethodShadowingBaseMethodCheck.cpp
@@ -65,7 +65,7 @@ AST_MATCHER(CXXMethodDecl, nameCollidesWithMethodInBase) {
for (const auto &BaseMethod : CurrentRecord->methods()) {
if (namesCollide(*BaseMethod, Node)) {
- ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
+ const ast_matchers::internal::BoundNodesTreeBuilder Result(*Builder);
Builder->setBinding("base_method",
clang::DynTypedNode::create(*BaseMethod));
return true;
diff --git a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
index 4d0428ec18598..48de7fbe7fad6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/DynamicStaticInitializersCheck.cpp
@@ -43,7 +43,7 @@ void DynamicStaticInitializersCheck::registerMatchers(MatchFinder *Finder) {
void DynamicStaticInitializersCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *Var = Result.Nodes.getNodeAs<VarDecl>("var");
- SourceLocation Loc = Var->getLocation();
+ const SourceLocation Loc = Var->getLocation();
if (!Loc.isValid() || !utils::isPresumedLocInHeaderFile(
Loc, *Result.SourceManager, HeaderFileExtensions))
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index b4ee35154f5f0..a07a68c8a3e65 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -417,7 +417,7 @@ struct MixData {
void sanitize() {
assert(Flags != MixFlags::Invalid && "sanitize() called on invalid bitvec");
- MixFlags CanonicalAndWorkaround =
+ const MixFlags CanonicalAndWorkaround =
MixFlags::Canonical | MixFlags::WorkaroundDisableCanonicalEquivalence;
if ((Flags & CanonicalAndWorkaround) == CanonicalAndWorkaround) {
// A workaround for too eagerly equivalent canonical types was requested,
@@ -483,7 +483,7 @@ struct MixData {
if (CommonType.isNull())
return *this;
- QualType NewCommonType = Func(CommonType);
+ const QualType NewCommonType = Func(CommonType);
if (CreatedFromOneWayConversion) {
MixData M{Flags, Conversion};
@@ -761,7 +761,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
return {MixFlags::None};
}
- MixData UnqualifiedMixability =
+ const MixData UnqualifiedMixability =
calculateMixability(Check, LType.getLocalUnqualifiedType(),
RType.getLocalUnqualifiedType(), Ctx, ImplicitMode)
.withCommonTypeTransformed([&AdditionalQuals, &Ctx](QualType QT) {
@@ -813,7 +813,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
if (ImplicitMode > ImplicitConversionModellingMode::None) {
LLVM_DEBUG(llvm::dbgs() << "--- calculateMixability. Start implicit...\n");
- MixData MixLTR =
+ const MixData MixLTR =
approximateImplicitConversion(Check, LType, RType, Ctx, ImplicitMode);
LLVM_DEBUG(
if (hasFlag(MixLTR.Flags, MixFlags::ImplicitConversion)) llvm::dbgs()
@@ -833,7 +833,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
// Otherwise if the invoker requested a full modelling, do the other
// direction as well.
- MixData MixRTL =
+ const MixData MixRTL =
approximateImplicitConversion(Check, RType, LType, Ctx, ImplicitMode);
LLVM_DEBUG(
if (hasFlag(MixRTL.Flags, MixFlags::ImplicitConversion)) llvm::dbgs()
@@ -868,7 +868,7 @@ calculateMixability(const TheCheck &Check, QualType LType, QualType RType,
// If none of the previous logic found a match, try if Clang otherwise
// believes the types to be the same.
- QualType LCanonical = LType.getCanonicalType();
+ const QualType LCanonical = LType.getCanonicalType();
if (LCanonical == RType.getCanonicalType()) {
LLVM_DEBUG(llvm::dbgs()
<< "<<< calculateMixability. Same CanonicalType.\n");
@@ -983,9 +983,9 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
// Numeric promotions and conversions.
const auto *FromBuiltin = WorkType->getAs<BuiltinType>();
const auto *ToBuiltin = To->getAs<BuiltinType>();
- bool FromNumeric = FromBuiltin && (FromBuiltin->isIntegerType() ||
- FromBuiltin->isFloatingType());
- bool ToNumeric =
+ const bool FromNumeric = FromBuiltin && (FromBuiltin->isIntegerType() ||
+ FromBuiltin->isFloatingType());
+ const bool ToNumeric =
ToBuiltin && (ToBuiltin->isIntegerType() || ToBuiltin->isFloatingType());
if (FromNumeric && ToNumeric) {
// If both are integral types, the numeric conversion is performed.
@@ -1150,9 +1150,9 @@ class UserDefinedConversionSelector {
continue;
}
- bool BestConversionHasImplicit =
+ const bool BestConversionHasImplicit =
hasFlag(BestConversion->Flags, MixFlags::ImplicitConversion);
- bool ThisConversionHasImplicit =
+ const bool ThisConversionHasImplicit =
hasFlag(Prepared.Flags, MixFlags::ImplicitConversion);
if (!BestConversionHasImplicit && ThisConversionHasImplicit)
// This is a worse conversion, because a better one was found earlier.
@@ -1221,7 +1221,7 @@ tryConversionOperators(const TheCheck &Check, const CXXRecordDecl *RD,
if (std::optional<UserDefinedConversionSelector::PreparedConversion>
SelectedConversion = ConversionSet()) {
- CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
+ const CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
ConversionSequence Result{RecordType, ToType};
// The conversion from the operator call's return type to ToType was
@@ -1272,7 +1272,7 @@ tryConvertingConstructors(const TheCheck &Check, QualType FromType,
if (std::optional<UserDefinedConversionSelector::PreparedConversion>
SelectedConversion = ConversionSet()) {
- CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
+ const CanQualType RecordType = RD->getASTContext().getCanonicalTagType(RD);
ConversionSequence Result{FromType, RecordType};
Result.AfterFirstStandard = SelectedConversion->Seq.AfterFirstStandard;
@@ -1385,7 +1385,7 @@ approximateImplicitConversion(const TheCheck &Check, QualType LType,
LLVM_DEBUG(
llvm::dbgs()
<< "--- approximateImplicitConversion. Try to find post-conversion.\n");
- MixData SecondStdConv = approximateImplicitConversion(
+ const MixData SecondStdConv = approximateImplicitConversion(
Check, WorkType, RType, Ctx,
ImplicitConversionModellingMode::OneWaySingleStandardOnly);
if (SecondStdConv.indicatesMixability()) {
@@ -1414,7 +1414,7 @@ approximateImplicitConversion(const TheCheck &Check, QualType LType,
static MixableParameterRange modelMixingRange(
const TheCheck &Check, const FunctionDecl *FD, std::size_t StartIndex,
const filter::SimilarlyUsedParameterPairSuppressor &UsageBasedSuppressor) {
- std::size_t NumParams = FD->getNumParams();
+ const std::size_t NumParams = FD->getNumParams();
assert(StartIndex < NumParams && "out of bounds for start");
const ASTContext &Ctx = FD->getASTContext();
@@ -1424,7 +1424,7 @@ static MixableParameterRange modelMixingRange(
for (std::size_t I = StartIndex + 1; I < NumParams; ++I) {
const ParmVarDecl *Ith = FD->getParamDecl(I);
- StringRef ParamName = Ith->getName();
+ const StringRef ParamName = Ith->getName();
LLVM_DEBUG(llvm::dbgs()
<< "Check param #" << I << " '" << ParamName << "'...\n");
if (filter::isIgnoredParameter(Check, Ith)) {
@@ -1432,7 +1432,7 @@ static MixableParameterRange modelMixingRange(
break;
}
- StringRef PrevParamName = FD->getParamDecl(I - 1)->getName();
+ const StringRef PrevParamName = FD->getParamDecl(I - 1)->getName();
if (!ParamName.empty() && !PrevParamName.empty() &&
filter::prefixSuffixCoverUnderThreshold(
Check.NamePrefixSuffixSilenceDissimilarityThreshold, PrevParamName,
@@ -1518,18 +1518,18 @@ static bool isIgnoredParameter(const TheCheck &Check, const ParmVarDecl *Node) {
if (!Node->getIdentifier())
return llvm::is_contained(Check.IgnoredParameterNames, "\"\"");
- StringRef NodeName = Node->getName();
+ const StringRef NodeName = Node->getName();
if (llvm::is_contained(Check.IgnoredParameterNames, NodeName)) {
LLVM_DEBUG(llvm::dbgs() << "\tName ignored.\n");
return true;
}
- StringRef NodeTypeName = [Node] {
+ const StringRef NodeTypeName = [Node] {
const ASTContext &Ctx = Node->getASTContext();
const SourceManager &SM = Ctx.getSourceManager();
SourceLocation B = Node->getTypeSpecStartLoc();
SourceLocation E = Node->getTypeSpecEndLoc();
- LangOptions LO;
+ const LangOptions LO;
LLVM_DEBUG(llvm::dbgs() << "\tType name code is '"
<< Lexer::getSourceText(
@@ -1633,7 +1633,7 @@ class AppearsInSameExpr : public RecursiveASTVisitor<AppearsInSameExpr> {
RootSetInCurrentStackFrame = true;
}
- bool Ret = Base::TraverseStmt(S);
+ const bool Ret = Base::TraverseStmt(S);
if (RootSetInCurrentStackFrame)
CurrentExprOnlyTreeRoot = nullptr;
@@ -1684,7 +1684,7 @@ class PassedToSameFunction {
continue;
std::optional<unsigned> TargetIdx;
- unsigned NumFnParams = CalledFn->getNumParams();
+ const unsigned NumFnParams = CalledFn->getNumParams();
for (unsigned Idx = 0; Idx < NumFnParams; ++Idx)
if (CalledFn->getParamDecl(Idx) == PassedToParam)
TargetIdx.emplace(Idx);
@@ -1837,16 +1837,16 @@ static void padStringAtBegin(SmallVectorImpl<char> &Str, std::size_t ToLen) {
static bool isCommonPrefixWithoutSomeCharacters(std::size_t N, StringRef S1,
StringRef S2) {
assert(S1.size() >= N && S2.size() >= N);
- StringRef S1Prefix = S1.take_front(S1.size() - N),
- S2Prefix = S2.take_front(S2.size() - N);
+ const StringRef S1Prefix = S1.take_front(S1.size() - N),
+ S2Prefix = S2.take_front(S2.size() - N);
return S1Prefix == S2Prefix && !S1Prefix.empty();
}
static bool isCommonSuffixWithoutSomeCharacters(std::size_t N, StringRef S1,
StringRef S2) {
assert(S1.size() >= N && S2.size() >= N);
- StringRef S1Suffix = S1.take_back(S1.size() - N),
- S2Suffix = S2.take_back(S2.size() - N);
+ const StringRef S1Suffix = S1.take_back(S1.size() - N),
+ S2Suffix = S2.take_back(S2.size() - N);
return S1Suffix == S2Suffix && !S1Suffix.empty();
}
@@ -1858,7 +1858,7 @@ static bool prefixSuffixCoverUnderThreshold(std::size_t Threshold,
return false;
// Pad the two strings to the longer length.
- std::size_t BiggerLength = std::max(Str1.size(), Str2.size());
+ const std::size_t BiggerLength = std::max(Str1.size(), Str2.size());
if (BiggerLength <= Threshold)
// If the length of the strings is still smaller than the threshold, they
@@ -1980,7 +1980,7 @@ struct FormattedConversionSequence {
// However, the parameter's defined type might not be what the implicit
// conversion started with, e.g. if a typedef is found to convert.
- std::string SeqBeginTypeStr = Conv.Begin.getAsString(PP);
+ const std::string SeqBeginTypeStr = Conv.Begin.getAsString(PP);
std::string SeqEndTypeStr = Conv.End.getAsString(PP);
if (StartTypeAsDiagnosed != SeqBeginTypeStr) {
OS << " (as '" << SeqBeginTypeStr << "')";
@@ -1995,7 +1995,7 @@ struct FormattedConversionSequence {
++NumElementsAdded;
}
};
- for (QualType InvolvedType : Conv.getInvolvedTypesInSequence())
+ for (const QualType InvolvedType : Conv.getInvolvedTypesInSequence())
// Print every type that's unique in the sequence into the diagnosis.
AddType(InvolvedType.getAsString(PP));
@@ -2073,12 +2073,14 @@ class UniqueTypeAliasDiagnosticHelper
if (CommonType.isNull() || CommonType == LHSType || CommonType == RHSType)
return Base::operator()({LHSType, RHSType, {}});
- TypeAliasDiagnosticTuple ThreeTuple{LHSType, RHSType, CommonType};
+ const TypeAliasDiagnosticTuple ThreeTuple{LHSType, RHSType, CommonType};
if (!Base::operator()(ThreeTuple))
return false;
- bool AlreadySaidLHSAndCommonIsSame = calledWith({LHSType, CommonType, {}});
- bool AlreadySaidRHSAndCommonIsSame = calledWith({RHSType, CommonType, {}});
+ const bool AlreadySaidLHSAndCommonIsSame =
+ calledWith({LHSType, CommonType, {}});
+ const bool AlreadySaidRHSAndCommonIsSame =
+ calledWith({RHSType, CommonType, {}});
if (AlreadySaidLHSAndCommonIsSame && AlreadySaidRHSAndCommonIsSame) {
// "SomeInt == int" && "SomeOtherInt == int" => "Common(SomeInt,
// SomeOtherInt) == int", no need to diagnose it. Save the 3-tuple only
@@ -2154,12 +2156,12 @@ void EasilySwappableParametersCheck::check(
assert(FD);
const PrintingPolicy &PP = FD->getASTContext().getPrintingPolicy();
- std::size_t NumParams = FD->getNumParams();
+ const std::size_t NumParams = FD->getNumParams();
std::size_t MixableRangeStartIndex = 0;
// Spawn one suppressor and if the user requested, gather information from
// the AST for the parameters' usages.
- filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor{
+ const filter::SimilarlyUsedParameterPairSuppressor UsageBasedSuppressor{
FD, SuppressParametersUsedTogether};
LLVM_DEBUG(llvm::dbgs() << "Begin analysis of " << getName(FD) << " with "
@@ -2182,11 +2184,13 @@ void EasilySwappableParametersCheck::check(
continue;
}
- bool NeedsAnyTypeNote = llvm::any_of(R.Mixes, needsToPrintTypeInDiagnostic);
- bool HasAnyImplicits =
+ const bool NeedsAnyTypeNote =
+ llvm::any_of(R.Mixes, needsToPrintTypeInDiagnostic);
+ const bool HasAnyImplicits =
llvm::any_of(R.Mixes, needsToElaborateImplicitConversion);
const ParmVarDecl *First = R.getFirstParam(), *Last = R.getLastParam();
- std::string FirstParamTypeAsWritten = First->getType().getAsString(PP);
+ const std::string FirstParamTypeAsWritten =
+ First->getType().getAsString(PP);
{
StringRef DiagText;
@@ -2205,7 +2209,7 @@ void EasilySwappableParametersCheck::check(
if (!NeedsAnyTypeNote)
Diag << FirstParamTypeAsWritten;
- CharSourceRange HighlightRange = CharSourceRange::getTokenRange(
+ const CharSourceRange HighlightRange = CharSourceRange::getTokenRange(
First->getBeginLoc(), Last->getEndLoc());
Diag << HighlightRange;
}
@@ -2240,12 +2244,12 @@ void EasilySwappableParametersCheck::check(
// emitted to a note diagnostic, so prepare it.
const ParmVarDecl *LVar = M.First;
const ParmVarDecl *RVar = M.Second;
- QualType LType = LVar->getType();
- QualType RType = RVar->getType();
- QualType CommonType = M.commonUnderlyingType();
- std::string LTypeStr = LType.getAsString(PP);
- std::string RTypeStr = RType.getAsString(PP);
- std::string CommonTypeStr = CommonType.getAsString(PP);
+ const QualType LType = LVar->getType();
+ const QualType RType = RVar->getType();
+ const QualType CommonType = M.commonUnderlyingType();
+ const std::string LTypeStr = LType.getAsString(PP);
+ const std::string RTypeStr = RType.getAsString(PP);
+ const std::string CommonTypeStr = CommonType.getAsString(PP);
if (hasFlag(M.flags(), MixFlags::TypeAlias) &&
UniqueTypeAlias(LType, RType, CommonType)) {
@@ -2274,8 +2278,9 @@ void EasilySwappableParametersCheck::check(
if ((hasFlag(M.flags(), MixFlags::ReferenceBind) ||
hasFlag(M.flags(), MixFlags::Qualifiers)) &&
UniqueBindPower({LType, RType})) {
- StringRef DiagText = "'%0' and '%1' parameters accept and bind the "
- "same kind of values";
+ const StringRef DiagText =
+ "'%0' and '%1' parameters accept and bind the "
+ "same kind of values";
diag(RVar->getOuterLocStart(), DiagText, DiagnosticIDs::Note)
<< LTypeStr << RTypeStr;
}
@@ -2286,8 +2291,8 @@ void EasilySwappableParametersCheck::check(
M.leftToRightConversionSequence();
const model::ConversionSequence &RTL =
M.rightToLeftConversionSequence();
- FormattedConversionSequence LTRFmt{PP, LTypeStr, LTR, RTypeStr};
- FormattedConversionSequence RTLFmt{PP, RTypeStr, RTL, LTypeStr};
+ const FormattedConversionSequence LTRFmt{PP, LTypeStr, LTR, RTypeStr};
+ const FormattedConversionSequence RTLFmt{PP, RTypeStr, RTL, LTypeStr};
StringRef DiagText = "'%0' and '%1' may be implicitly converted";
if (!LTRFmt.Trivial || !RTLFmt.Trivial)
@@ -2302,7 +2307,7 @@ void EasilySwappableParametersCheck::check(
Diag << LTRFmt.DiagnosticText << RTLFmt.DiagnosticText;
}
- StringRef ConversionFunctionDiagText =
+ const StringRef ConversionFunctionDiagText =
"the implicit conversion involves the "
"%select{|converting constructor|conversion operator}0 "
"declared here";
diff --git a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
index eebab847d1070..5dd2f62504c71 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EmptyCatchCheck.cpp
@@ -25,7 +25,7 @@ AST_MATCHER(CXXCatchStmt, isInMacro) {
}
AST_MATCHER_P(CXXCatchStmt, hasHandler, Matcher<Stmt>, InnerMatcher) {
- Stmt *Handler = Node.getHandlerBlock();
+ const Stmt *Handler = Node.getHandlerBlock();
if (!Handler)
return false;
return InnerMatcher.matches(*Handler, Finder, Builder);
@@ -41,7 +41,7 @@ AST_MATCHER_P(CompoundStmt, hasAnyTextFromList, std::vector<llvm::StringRef>,
return false;
ASTContext &Context = Finder->getASTContext();
- SourceManager &SM = Context.getSourceManager();
+ const SourceManager &SM = Context.getSourceManager();
StringRef Text = Lexer::getSourceText(
CharSourceRange::getTokenRange(Node.getSourceRange()), SM,
Context.getLangOpts());
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
index c3db8fa9b3af2..11270e7f34d79 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardDeclarationNamespaceCheck.cpp
@@ -46,7 +46,7 @@ void ForwardDeclarationNamespaceCheck::check(
const MatchFinder::MatchResult &Result) {
if (const auto *RecordDecl =
Result.Nodes.getNodeAs<CXXRecordDecl>("record_decl")) {
- StringRef DeclName = RecordDecl->getName();
+ const StringRef DeclName = RecordDecl->getName();
if (RecordDecl->isThisDeclarationADefinition()) {
DeclNameToDefinitions[DeclName].push_back(RecordDecl);
} else {
diff --git a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
index d372cbd798b2e..c1e66f210b8b2 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ForwardingReferenceOverloadCheck.cpp
@@ -40,7 +40,7 @@ AST_MATCHER(QualType, isEnableIf) {
if (CheckTemplate(BaseType->getAs<TemplateSpecializationType>()))
return true; // Case: enable_if_t< >.
if (const auto *TT = BaseType->getAs<TypedefType>())
- if (NestedNameSpecifier Q = TT->getQualifier();
+ if (const NestedNameSpecifier Q = TT->getQualifier();
Q.getKind() == NestedNameSpecifier::Kind::Type)
if (CheckTemplate(Q.getAsType()->getAs<TemplateSpecializationType>()))
return true; // Case: enable_if< >::type.
@@ -67,7 +67,7 @@ void ForwardingReferenceOverloadCheck::registerMatchers(MatchFinder *Finder) {
unless(references(isConstQualified())))))
.bind("parm-var");
- DeclarationMatcher FindOverload =
+ const DeclarationMatcher FindOverload =
cxxConstructorDecl(
hasParameter(0, ForwardingRefParm), unless(isDeleted()),
unless(hasAnyParameter(
@@ -128,8 +128,9 @@ void ForwardingReferenceOverloadCheck::check(
(OtherCtor->isCopyConstructor() ? EnabledCopy : EnabledMove) = true;
}
}
- bool Copy = (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
- bool Move = !DisabledMove || EnabledMove;
+ const bool Copy =
+ (!EnabledMove && !DisabledMove && !DisabledCopy) || EnabledCopy;
+ const bool Move = !DisabledMove || EnabledMove;
if (!Copy && !Move)
return;
diag(Ctor->getLocation(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
index 2211a0ba24ebc..634d54c2b9bd3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/ImplicitWideningOfMultiplicationResultCheck.cpp
@@ -71,18 +71,18 @@ ImplicitWideningOfMultiplicationResultCheck::includeStddefHeader(
void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
const ImplicitCastExpr *ICE) {
- ASTContext *Context = Result->Context;
+ const ASTContext *Context = Result->Context;
const Expr *E = ICE->getSubExpr()->IgnoreParens();
- QualType Ty = ICE->getType();
- QualType ETy = E->getType();
+ const QualType Ty = ICE->getType();
+ const QualType ETy = E->getType();
assert(!ETy->isDependentType() && !Ty->isDependentType() &&
"Don't expect to ever get here in template Context.");
// This must be a widening cast. Else we do not care.
- unsigned SrcWidth = Context->getIntWidth(ETy);
- unsigned TgtWidth = Context->getIntWidth(Ty);
+ const unsigned SrcWidth = Context->getIntWidth(ETy);
+ const unsigned TgtWidth = Context->getIntWidth(Ty);
if (TgtWidth <= SrcWidth)
return;
@@ -92,7 +92,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
!ETy->isUnsignedIntegerType()) {
if (const auto ConstExprResult = E->getIntegerConstantExpr(*Context)) {
const auto TypeSize = Context->getTypeSize(ETy);
- llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
+ const llvm::APSInt WidenedResult = ConstExprResult->extOrTrunc(TypeSize);
if (WidenedResult <= llvm::APSInt::getMaxValue(TypeSize, false) &&
WidenedResult >= llvm::APSInt::getMinValue(TypeSize, false))
return;
@@ -168,7 +168,7 @@ void ImplicitWideningOfMultiplicationResultCheck::handleImplicitCastExpr(
void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
const Expr *E) {
- ASTContext *Context = Result->Context;
+ const ASTContext *Context = Result->Context;
// We are looking for a pointer offset operation,
// with one hand being a pointer, and another one being an offset.
@@ -191,19 +191,20 @@ void ImplicitWideningOfMultiplicationResultCheck::handlePointerOffsetting(
IndexExpr = IndexExpr->IgnoreParens();
- QualType IndexExprType = IndexExpr->getType();
+ const QualType IndexExprType = IndexExpr->getType();
// If the index expression's type is not known (i.e. we are in a template),
// we can't do anything here.
if (IndexExprType->isDependentType())
return;
- QualType SSizeTy = Context->getPointerDiffType();
- QualType USizeTy = Context->getSizeType();
- QualType SizeTy = IndexExprType->isSignedIntegerType() ? SSizeTy : USizeTy;
+ const QualType SSizeTy = Context->getPointerDiffType();
+ const QualType USizeTy = Context->getSizeType();
+ const QualType SizeTy =
+ IndexExprType->isSignedIntegerType() ? SSizeTy : USizeTy;
// FIXME: is there a way to actually get the QualType for size_t/ptr
diff _t?
// Note that SizeTy.getAsString() will be unsigned long/..., NOT size_t!
- StringRef TyAsString =
+ const StringRef TyAsString =
IndexExprType->isSignedIntegerType() ? "ptr
diff _t" : "size_t";
// So, is size_t actually wider than the result of the multiplication?
diff --git a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
index b0dd9017c8426..12fa3655ffcd6 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InaccurateEraseCheck.cpp
@@ -43,7 +43,7 @@ void InaccurateEraseCheck::check(const MatchFinder::MatchResult &Result) {
if (!Loc.isMacroID() && EndExpr) {
const auto *AlgCall = Result.Nodes.getNodeAs<CallExpr>("alg");
- std::string ReplacementText = std::string(Lexer::getSourceText(
+ const std::string ReplacementText = std::string(Lexer::getSourceText(
CharSourceRange::getTokenRange(EndExpr->getSourceRange()),
*Result.SourceManager, getLangOpts()));
const SourceLocation EndLoc = Lexer::getLocForEndOfToken(
diff --git a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
index 84a99c36523ac..6181ac84f36e3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/IncorrectEnableIfCheck.cpp
@@ -22,7 +22,7 @@ AST_MATCHER_P(TemplateTypeParmDecl, hasUnnamedDefaultArgument,
Node.getDefaultArgument().getArgument().isNull())
return false;
- TypeLoc DefaultArgTypeLoc =
+ const TypeLoc DefaultArgTypeLoc =
Node.getDefaultArgument().getTypeSourceInfo()->getTypeLoc();
return InnerMatcher.matches(DefaultArgTypeLoc, Finder, Builder);
}
@@ -51,7 +51,7 @@ void IncorrectEnableIfCheck::check(const MatchFinder::MatchResult &Result) {
return;
const SourceManager &SM = *Result.SourceManager;
- SourceLocation RAngleLoc =
+ const SourceLocation RAngleLoc =
SM.getExpansionLoc(EnableIfSpecializationLoc->getRAngleLoc());
auto Diag = diag(EnableIf->getBeginLoc(),
diff --git a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
index 1e516c1573219..50280d22be0d8 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InfiniteLoopCheck.cpp
@@ -34,7 +34,7 @@ AST_MATCHER(FunctionType, typeHasNoReturnAttr) {
} // namespace
static Matcher<Stmt> loopEndingStmt(Matcher<Stmt> Internal) {
- Matcher<QualType> IsNoReturnFunType =
+ const Matcher<QualType> IsNoReturnFunType =
ignoringParens(functionType(typeHasNoReturnAttr()));
Matcher<Decl> IsNoReturnDecl =
anyOf(declHasNoReturnAttr(), functionDecl(hasType(IsNoReturnFunType)),
@@ -145,7 +145,7 @@ static std::string getCondVarNames(const Stmt *Cond) {
if (!Child)
continue;
- std::string NewNames = getCondVarNames(Child);
+ const std::string NewNames = getCondVarNames(Child);
if (!Result.empty() && !NewNames.empty())
Result += ", ";
Result += NewNames;
@@ -332,7 +332,7 @@ void InfiniteLoopCheck::check(const MatchFinder::MatchResult &Result) {
Result.Context))
return;
- std::string CondVarNames = getCondVarNames(Cond);
+ const std::string CondVarNames = getCondVarNames(Cond);
if (ShouldHaveConditionVariables && CondVarNames.empty())
return;
diff --git a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
index 18eb40f4eb6d2..f3e94b62f0dbd 100644
--- a/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/InvalidEnumDefaultInitializationCheck.cpp
@@ -151,7 +151,7 @@ void InvalidEnumDefaultInitializationCheck::check(
SourceLocation Loc = InitExpr->getExprLoc();
if (Loc.isInvalid()) {
if (isa<ImplicitValueInitExpr, InitListExpr>(InitExpr)) {
- DynTypedNodeList Parents = ACtx.getParents(*InitExpr);
+ const DynTypedNodeList Parents = ACtx.getParents(*InitExpr);
if (Parents.empty())
return;
@@ -170,7 +170,7 @@ void InvalidEnumDefaultInitializationCheck::check(
// The expression may be implicitly generated for an initialization.
// Search for a parent initialization list with valid source location.
while (InitList->getExprLoc().isInvalid()) {
- DynTypedNodeList Parents = ACtx.getParents(*InitList);
+ const DynTypedNodeList Parents = ACtx.getParents(*InitList);
if (Parents.empty())
return;
InitList = Parents[0].get<InitListExpr>();
diff --git a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
index fb73e896fdb13..1f666d2a4345f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/LambdaFunctionNameCheck.cpp
@@ -40,7 +40,7 @@ class MacroExpansionsWithFileAndLine : public PPCallbacks {
bool HasLine = false;
for (const Token &T : MD.getMacroInfo()->tokens()) {
if (T.is(tok::identifier)) {
- StringRef IdentName = T.getIdentifierInfo()->getName();
+ const StringRef IdentName = T.getIdentifierInfo()->getName();
if (IdentName == "__FILE__") {
HasFile = true;
} else if (IdentName == "__LINE__") {
diff --git a/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
index 78a53d12bd312..c79320fbf3304 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MacroRepeatedSideEffectsCheck.cpp
@@ -127,7 +127,7 @@ unsigned MacroRepeatedPPCallbacks::countArgumentExpansions(
continue;
}
- IdentifierInfo *TII = T.getIdentifierInfo();
+ const IdentifierInfo *TII = T.getIdentifierInfo();
// If not existent, skip it.
if (TII == nullptr)
continue;
More information about the cfe-commits
mailing list