@@ -115,7 +115,7 @@ arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
115115// / - The index variable is only used as an array index.
116116// / - All arrays indexed by the loop are the same.
117117static StatementMatcher makeArrayLoopMatcher () {
118- StatementMatcher ArrayBoundMatcher =
118+ const StatementMatcher ArrayBoundMatcher =
119119 expr (hasType (isInteger ())).bind (ConditionBoundName);
120120
121121 return forStmt (unless (isInTemplateInstantiation ()),
@@ -168,7 +168,7 @@ static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
168168 auto EndNameMatcherStd = IsReverse ? hasAnyName (" ::std::rend" , " ::std::crend" )
169169 : hasAnyName (" ::std::end" , " ::std::cend" );
170170
171- StatementMatcher BeginCallMatcher =
171+ const StatementMatcher BeginCallMatcher =
172172 expr (anyOf (cxxMemberCallExpr (argumentCountIs (0 ),
173173 callee (cxxMethodDecl (BeginNameMatcher))),
174174 callExpr (argumentCountIs (1 ),
@@ -177,37 +177,37 @@ static StatementMatcher makeIteratorLoopMatcher(bool IsReverse) {
177177 callee (functionDecl (BeginNameMatcherStd)))))
178178 .bind (BeginCallName);
179179
180- DeclarationMatcher InitDeclMatcher =
180+ const DeclarationMatcher InitDeclMatcher =
181181 varDecl (hasInitializer (anyOf (ignoringParenImpCasts (BeginCallMatcher),
182182 materializeTemporaryExpr (
183183 ignoringParenImpCasts (BeginCallMatcher)),
184184 hasDescendant (BeginCallMatcher))))
185185 .bind (InitVarName);
186186
187- DeclarationMatcher EndDeclMatcher =
187+ const DeclarationMatcher EndDeclMatcher =
188188 varDecl (hasInitializer (anything ())).bind (EndVarName);
189189
190- StatementMatcher EndCallMatcher = expr (anyOf (
190+ const StatementMatcher EndCallMatcher = expr (anyOf (
191191 cxxMemberCallExpr (argumentCountIs (0 ),
192192 callee (cxxMethodDecl (EndNameMatcher))),
193193 callExpr (argumentCountIs (1 ), callee (functionDecl (EndNameMatcher)),
194194 usesADL ()),
195195 callExpr (argumentCountIs (1 ), callee (functionDecl (EndNameMatcherStd)))));
196196
197- StatementMatcher IteratorBoundMatcher =
197+ const StatementMatcher IteratorBoundMatcher =
198198 expr (anyOf (ignoringParenImpCasts (
199199 declRefExpr (to (varDecl (equalsBoundNode (EndVarName))))),
200200 ignoringParenImpCasts (expr (EndCallMatcher).bind (EndCallName)),
201201 materializeTemporaryExpr (ignoringParenImpCasts (
202202 expr (EndCallMatcher).bind (EndCallName)))));
203203
204- StatementMatcher IteratorComparisonMatcher = expr (ignoringParenImpCasts (
204+ const StatementMatcher IteratorComparisonMatcher = expr (ignoringParenImpCasts (
205205 declRefExpr (to (varDecl (equalsBoundNode (InitVarName))))));
206206
207207 // This matcher tests that a declaration is a CXXRecordDecl that has an
208208 // overloaded operator*(). If the operator*() returns by value instead of by
209209 // reference then the return type is tagged with DerefByValueResultName.
210- internal::Matcher<VarDecl> TestDerefReturnsByValue =
210+ const internal::Matcher<VarDecl> TestDerefReturnsByValue =
211211 hasType (hasUnqualifiedDesugaredType (
212212 recordType (hasDeclaration (cxxRecordDecl (hasMethod (cxxMethodDecl (
213213 hasOverloadedOperatorName (" *" ),
@@ -280,7 +280,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
280280 // FIXME: Also, a record doesn't necessarily need begin() and end(). Free
281281 // functions called begin() and end() taking the container as an argument
282282 // are also allowed.
283- TypeMatcher RecordWithBeginEnd = qualType (anyOf (
283+ const TypeMatcher RecordWithBeginEnd = qualType (anyOf (
284284 qualType (isConstQualified (),
285285 hasUnqualifiedDesugaredType (recordType (hasDeclaration (
286286 cxxRecordDecl (isSameOrDerivedFrom (cxxRecordDecl (
@@ -295,7 +295,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
295295 hasMethod (hasName (" end" ))))))))) // qualType
296296 ));
297297
298- StatementMatcher SizeCallMatcher = expr (anyOf (
298+ const StatementMatcher SizeCallMatcher = expr (anyOf (
299299 cxxMemberCallExpr (argumentCountIs (0 ),
300300 callee (cxxMethodDecl (hasAnyName (" size" , " length" ))),
301301 on (anyOf (hasType (pointsTo (RecordWithBeginEnd)),
@@ -310,10 +310,10 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
310310 explicitCastExpr (hasSourceExpression (ignoringParenImpCasts (
311311 expr (SizeCallMatcher).bind (EndCallName))))));
312312
313- DeclarationMatcher EndDeclMatcher =
313+ const DeclarationMatcher EndDeclMatcher =
314314 varDecl (hasInitializer (EndInitMatcher)).bind (EndVarName);
315315
316- StatementMatcher IndexBoundMatcher =
316+ const StatementMatcher IndexBoundMatcher =
317317 expr (anyOf (ignoringParenImpCasts (
318318 declRefExpr (to (varDecl (equalsBoundNode (EndVarName))))),
319319 EndInitMatcher));
@@ -620,7 +620,7 @@ void LoopConvertCheck::getAliasRange(SourceManager &SM, SourceRange &Range) {
620620 SM.getCharacterData (Range.getEnd ().getLocWithOffset (1 ), &Invalid);
621621 if (Invalid)
622622 return ;
623- unsigned Offset = std::strspn (TextAfter, " \t\r\n " );
623+ const unsigned Offset = std::strspn (TextAfter, " \t\r\n " );
624624 Range =
625625 SourceRange (Range.getBegin (), Range.getEnd ().getLocWithOffset (Offset));
626626}
@@ -633,7 +633,7 @@ void LoopConvertCheck::doConversion(
633633 const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
634634 const ForStmt *Loop, RangeDescriptor Descriptor) {
635635 std::string VarNameOrStructuredBinding;
636- bool VarNameFromAlias = (Usages.size () == 1 ) && AliasDecl;
636+ const bool VarNameFromAlias = (Usages.size () == 1 ) && AliasDecl;
637637 bool AliasVarIsRef = false ;
638638 bool CanCopy = true ;
639639 std::vector<FixItHint> FixIts;
@@ -743,7 +743,7 @@ void LoopConvertCheck::doConversion(
743743 }
744744
745745 // Now, we need to construct the new range expression.
746- SourceRange ParenRange (Loop->getLParenLoc (), Loop->getRParenLoc ());
746+ const SourceRange ParenRange (Loop->getLParenLoc (), Loop->getRParenLoc ());
747747
748748 QualType Type = Context->getAutoDeductType ();
749749 if (!Descriptor.ElemType .isNull () && Descriptor.ElemType ->isFundamentalType ())
@@ -753,14 +753,15 @@ void LoopConvertCheck::doConversion(
753753 // If the new variable name is from the aliased variable, then the reference
754754 // type for the new variable should only be used if the aliased variable was
755755 // declared as a reference.
756- bool IsCheapToCopy =
756+ const bool IsCheapToCopy =
757757 !Descriptor.ElemType .isNull () &&
758758 Descriptor.ElemType .isTriviallyCopyableType (*Context) &&
759759 !Descriptor.ElemType ->isDependentSizedArrayType () &&
760760 // TypeInfo::Width is in bits.
761761 Context->getTypeInfo (Descriptor.ElemType ).Width <= 8 * MaxCopySize;
762- bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
763- (Descriptor.DerefByConstRef && IsCheapToCopy));
762+ const bool UseCopy =
763+ CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
764+ (Descriptor.DerefByConstRef && IsCheapToCopy));
764765
765766 if (!UseCopy) {
766767 if (Descriptor.DerefByConstRef ) {
@@ -866,7 +867,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext *Context,
866867 // The matchers for iterator loops provide bound nodes to obtain this
867868 // information.
868869 const auto *InitVar = Nodes.getNodeAs <VarDecl>(InitVarName);
869- QualType CanonicalInitVarType = InitVar->getType ().getCanonicalType ();
870+ const QualType CanonicalInitVarType = InitVar->getType ().getCanonicalType ();
870871 const auto *DerefByValueType =
871872 Nodes.getNodeAs <QualType>(DerefByValueResultName);
872873 Descriptor.DerefByValue = DerefByValueType;
@@ -934,12 +935,12 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
934935
935936 // FIXME: Try to put most of this logic inside a matcher.
936937 if (FixerKind == LFK_Iterator || FixerKind == LFK_ReverseIterator) {
937- QualType InitVarType = InitVar->getType ();
938- QualType CanonicalInitVarType = InitVarType.getCanonicalType ();
938+ const QualType InitVarType = InitVar->getType ();
939+ const QualType CanonicalInitVarType = InitVarType.getCanonicalType ();
939940
940941 const auto *BeginCall = Nodes.getNodeAs <CallExpr>(BeginCallName);
941942 assert (BeginCall && " Bad Callback. No begin call expression" );
942- QualType CanonicalBeginType =
943+ const QualType CanonicalBeginType =
943944 BeginCall->getDirectCallee ()->getReturnType ().getCanonicalType ();
944945 if (CanonicalBeginType->isPointerType () &&
945946 CanonicalInitVarType->isPointerType ()) {
@@ -1054,7 +1055,7 @@ void LoopConvertCheck::check(const MatchFinder::MatchResult &Result) {
10541055 }
10551056
10561057 // Find out which qualifiers we have to use in the loop range.
1057- TraversalKindScope RAII (*Context, TK_AsIs);
1058+ const TraversalKindScope RAII (*Context, TK_AsIs);
10581059 const UsageResult &Usages = Finder.getUsages ();
10591060 determineRangeDescriptor (Context, Nodes, Loop, FixerKind, ContainerExpr,
10601061 Usages, Descriptor);
0 commit comments