https://github.com/vbvictor created 
https://github.com/llvm/llvm-project/pull/167127

None

>From 7f763c172a255a555b6bd7f36e4be4dfc1a6580e Mon Sep 17 00:00:00 2001
From: Victor Baranov <[email protected]>
Date: Sat, 8 Nov 2025 14:39:27 +0300
Subject: [PATCH] [clang-tidy][NFC] Fix misc-const-correctness warnings (10/N)

---
 .../clang-tidy/modernize/AvoidBindCheck.cpp   | 20 ++++----
 .../modernize/ConcatNestedNamespacesCheck.cpp | 18 +++----
 .../modernize/DeprecatedHeadersCheck.cpp      |  2 +-
 .../DeprecatedIosBaseAliasesCheck.cpp         |  7 +--
 .../IntegralLiteralExpressionMatcher.cpp      |  2 +-
 .../clang-tidy/modernize/LoopConvertCheck.cpp | 47 ++++++++++---------
 .../clang-tidy/modernize/LoopConvertUtils.cpp | 19 ++++----
 .../clang-tidy/modernize/MacroToEnumCheck.cpp | 36 +++++++-------
 .../modernize/MakeSmartPtrCheck.cpp           | 38 +++++++--------
 .../clang-tidy/modernize/PassByValueCheck.cpp | 15 +++---
 .../modernize/RawStringLiteralCheck.cpp       | 10 ++--
 .../modernize/RedundantVoidArgCheck.cpp       | 24 +++++-----
 .../modernize/ReplaceAutoPtrCheck.cpp         |  7 +--
 ...ReplaceDisallowCopyAndAssignMacroCheck.cpp |  6 +--
 .../modernize/ReplaceRandomShuffleCheck.cpp   |  2 +-
 .../modernize/ReturnBracedInitListCheck.cpp   |  4 +-
 .../clang-tidy/modernize/TypeTraitsCheck.cpp  |  4 +-
 .../modernize/UnaryStaticAssertCheck.cpp      |  2 +-
 .../clang-tidy/modernize/UseAutoCheck.cpp     | 43 +++++++++--------
 .../modernize/UseBoolLiteralsCheck.cpp        |  4 +-
 .../modernize/UseConstraintsCheck.cpp         | 32 ++++++-------
 21 files changed, 177 insertions(+), 165 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
index 1c0043b423361..531311e732290 100644
--- a/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
@@ -252,7 +252,7 @@ static SmallVector<BindArgument, 4>
 buildBindArguments(const MatchFinder::MatchResult &Result,
                    const CallableInfo &Callable) {
   SmallVector<BindArgument, 4> BindArguments;
-  static llvm::Regex MatchPlaceholder("^_([0-9]+)$");
+  static const llvm::Regex MatchPlaceholder("^_([0-9]+)$");
 
   const auto *BindCall = Result.Nodes.getNodeAs<CallExpr>("bind");
 
@@ -267,7 +267,7 @@ buildBindArguments(const MatchFinder::MatchResult &Result,
     if (Callable.Type == CT_MemberFunction)
       --ArgIndex;
 
-    bool IsObjectPtr = (I == 1 && Callable.Type == CT_MemberFunction);
+    const bool IsObjectPtr = (I == 1 && Callable.Type == CT_MemberFunction);
     B.E = E;
     B.SourceTokens = getSourceTextForExpr(Result, E);
 
@@ -340,13 +340,13 @@ static void addPlaceholderArgs(const LambdaProperties &LP,
                                    MaxPlaceholderIt->PlaceHolderIndex == 0))
     return;
 
-  size_t PlaceholderCount = MaxPlaceholderIt->PlaceHolderIndex;
+  const size_t PlaceholderCount = MaxPlaceholderIt->PlaceHolderIndex;
   Stream << "(";
   StringRef Delimiter = "";
   for (size_t I = 1; I <= PlaceholderCount; ++I) {
     Stream << Delimiter << "auto &&";
 
-    int ArgIndex = findPositionOfPlaceholderUse(Args, I);
+    const int ArgIndex = findPositionOfPlaceholderUse(Args, I);
 
     if (ArgIndex != -1 && Args[ArgIndex].IsUsed)
       Stream << " " << Args[ArgIndex].UsageIdentifier;
@@ -392,7 +392,7 @@ findCandidateCallOperators(const CXXRecordDecl *RecordDecl, 
size_t NumArgs) {
   std::vector<const FunctionDecl *> Candidates;
 
   for (const clang::CXXMethodDecl *Method : RecordDecl->methods()) {
-    OverloadedOperatorKind OOK = Method->getOverloadedOperator();
+    const OverloadedOperatorKind OOK = Method->getOverloadedOperator();
 
     if (OOK != OverloadedOperatorKind::OO_Call)
       continue;
@@ -410,7 +410,7 @@ findCandidateCallOperators(const CXXRecordDecl *RecordDecl, 
size_t NumArgs) {
       continue;
     const FunctionDecl *FD = FTD->getTemplatedDecl();
 
-    OverloadedOperatorKind OOK = FD->getOverloadedOperator();
+    const OverloadedOperatorKind OOK = FD->getOverloadedOperator();
     if (OOK != OverloadedOperatorKind::OO_Call)
       continue;
 
@@ -471,7 +471,7 @@ getCallMethodDecl(const MatchFinder::MatchResult &Result, 
CallableType Type,
 
   if (Type == CT_Object) {
     const auto *BindCall = Result.Nodes.getNodeAs<CallExpr>("bind");
-    size_t NumArgs = BindCall->getNumArgs() - 1;
+    const size_t NumArgs = BindCall->getNumArgs() - 1;
     return getCallOperator(Callee->getType()->getAsCXXRecordDecl(), NumArgs);
   }
 
@@ -488,7 +488,7 @@ getCallMethodDecl(const MatchFinder::MatchResult &Result, 
CallableType Type,
 static CallableType getCallableType(const MatchFinder::MatchResult &Result) {
   const auto *CallableExpr = Result.Nodes.getNodeAs<Expr>("ref");
 
-  QualType QT = CallableExpr->getType();
+  const QualType QT = CallableExpr->getType();
   if (QT->isMemberFunctionPointerType())
     return CT_MemberFunction;
 
@@ -614,7 +614,7 @@ static void emitCaptureList(const LambdaProperties &LP,
     if (B.CM == CM_None || !B.IsUsed)
       continue;
 
-    StringRef Delimiter = AnyCapturesEmitted ? ", " : "";
+    const StringRef Delimiter = AnyCapturesEmitted ? ", " : "";
 
     if (emitCapture(CaptureSet, Delimiter, B.CM, B.CE, B.CaptureIdentifier,
                     B.SourceTokens, Stream))
@@ -669,7 +669,7 @@ void AvoidBindCheck::check(const MatchFinder::MatchResult 
&Result) {
   emitCaptureList(LP, Result, Stream);
   Stream << "]";
 
-  ArrayRef<BindArgument> FunctionCallArgs = ArrayRef(LP.BindArguments);
+  const ArrayRef<BindArgument> FunctionCallArgs = ArrayRef(LP.BindArguments);
 
   addPlaceholderArgs(LP, Stream, PermissiveParameterList);
 
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
index 6e28cb223370a..7c82e9ef029ba 100644
--- a/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
@@ -25,7 +25,8 @@ static bool locationsInSameFile(const SourceManager &Sources,
 static StringRef getRawStringRef(const SourceRange &Range,
                                  const SourceManager &Sources,
                                  const LangOptions &LangOpts) {
-  CharSourceRange TextRange = Lexer::getAsCharRange(Range, Sources, LangOpts);
+  const CharSourceRange TextRange =
+      Lexer::getAsCharRange(Range, Sources, LangOpts);
   return Lexer::getSourceText(TextRange, Sources, LangOpts);
 }
 
@@ -56,15 +57,16 @@ SourceRange NS::getDefaultNamespaceBackRange() const {
 SourceRange NS::getNamespaceBackRange(const SourceManager &SM,
                                       const LangOptions &LangOpts) const {
   // Back from '}' to conditional '// namespace xxx'
-  SourceLocation Loc = front()->getRBraceLoc();
+  const SourceLocation Loc = front()->getRBraceLoc();
   std::optional<Token> Tok =
       utils::lexer::findNextTokenIncludingComments(Loc, SM, LangOpts);
   if (!Tok)
     return getDefaultNamespaceBackRange();
   if (Tok->getKind() != tok::TokenKind::comment)
     return getDefaultNamespaceBackRange();
-  SourceRange TokRange = SourceRange{Tok->getLocation(), Tok->getEndLoc()};
-  StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
+  const SourceRange TokRange =
+      SourceRange{Tok->getLocation(), Tok->getEndLoc()};
+  const StringRef TokText = getRawStringRef(TokRange, SM, LangOpts);
   NamespaceName CloseComment{"namespace "};
   appendCloseComment(CloseComment);
   // current fix hint in readability/NamespaceCommentCheck.cpp use single line
@@ -98,7 +100,7 @@ bool ConcatNestedNamespacesCheck::unsupportedNamespace(const 
NamespaceDecl &ND,
     return true;
   if (getLangOpts().CPlusPlus20) {
     // C++20 support inline nested namespace
-    bool IsFirstNS = IsChild || !Namespaces.empty();
+    const bool IsFirstNS = IsChild || !Namespaces.empty();
     return ND.isInlineNamespace() && !IsFirstNS;
   }
   return ND.isInlineNamespace();
@@ -106,7 +108,7 @@ bool 
ConcatNestedNamespacesCheck::unsupportedNamespace(const NamespaceDecl &ND,
 
 bool ConcatNestedNamespacesCheck::singleNamedNamespaceChild(
     const NamespaceDecl &ND) const {
-  NamespaceDecl::decl_range Decls = ND.decls();
+  const NamespaceDecl::decl_range Decls = ND.decls();
   if (std::distance(Decls.begin(), Decls.end()) != 1)
     return false;
 
@@ -121,7 +123,7 @@ void ConcatNestedNamespacesCheck::registerMatchers(
 
 void ConcatNestedNamespacesCheck::reportDiagnostic(
     const SourceManager &SM, const LangOptions &LangOpts) {
-  DiagnosticBuilder DB =
+  const DiagnosticBuilder DB =
       diag(Namespaces.front().front()->getBeginLoc(),
            "nested namespaces can be concatenated", DiagnosticIDs::Warning);
 
@@ -143,7 +145,7 @@ void ConcatNestedNamespacesCheck::reportDiagnostic(
 
   // the last one should be handled specially
   Fronts.pop_back();
-  SourceRange LastRBrace = Backs.pop_back_val();
+  const SourceRange LastRBrace = Backs.pop_back_val();
 
   NamespaceName ConcatNameSpace{"namespace "};
   for (const NS &NS : Namespaces) {
diff --git a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
index 1de9e136c5719..21eefab843af9 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
@@ -184,7 +184,7 @@ void IncludeModernizePPCallbacks::InclusionDirective(
   // 1. Insert std prefix for every such symbol occurrence.
   // 2. Insert `using namespace std;` to the beginning of TU.
   // 3. Do nothing and let the user deal with the migration himself.
-  SourceLocation DiagLoc = FilenameRange.getBegin();
+  const SourceLocation DiagLoc = FilenameRange.getBegin();
   if (auto It = CStyledHeaderToCxx.find(FileName);
       It != CStyledHeaderToCxx.end()) {
     IncludesToBeProcessed.emplace_back(IncludeMarker{
diff --git 
a/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
index 5e254376c9796..7e43165fb09f1 100644
--- a/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/DeprecatedIosBaseAliasesCheck.cpp
@@ -36,10 +36,10 @@ void 
DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
 
 void DeprecatedIosBaseAliasesCheck::check(
     const MatchFinder::MatchResult &Result) {
-  SourceManager &SM = *Result.SourceManager;
+  const SourceManager &SM = *Result.SourceManager;
 
   const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
-  StringRef TypeName = Typedef->getName();
+  const StringRef TypeName = Typedef->getName();
   auto Replacement = getReplacementType(TypeName);
 
   TypeLoc TL = *Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
@@ -55,7 +55,8 @@ void DeprecatedIosBaseAliasesCheck::check(
     Fix = false;
   }
 
-  SourceLocation EndLoc = IoStateLoc.getLocWithOffset(TypeName.size() - 1);
+  const SourceLocation EndLoc =
+      IoStateLoc.getLocWithOffset(TypeName.size() - 1);
 
   if (Replacement) {
     const char *FixName = *Replacement;
diff --git 
a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp 
b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
index 05cf51a430f3f..862ca184ecd97 100644
--- 
a/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
+++ 
b/clang-tools-extra/clang-tidy/modernize/IntegralLiteralExpressionMatcher.cpp
@@ -95,7 +95,7 @@ bool IntegralLiteralExpressionMatcher::unaryOperator() {
 }
 
 static LiteralSize literalTokenSize(const Token &Tok) {
-  unsigned int Length = Tok.getLength();
+  const unsigned int Length = Tok.getLength();
   if (Length <= 1)
     return LiteralSize::Int;
 
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index fea5ac6f29eff..30e2d4fe0a372 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -115,7 +115,7 @@ arrayConditionMatcher(internal::Matcher<Expr> LimitExpr) {
 ///   - The index variable is only used as an array index.
 ///   - All arrays indexed by the loop are the same.
 static StatementMatcher makeArrayLoopMatcher() {
-  StatementMatcher ArrayBoundMatcher =
+  const StatementMatcher ArrayBoundMatcher =
       expr(hasType(isInteger())).bind(ConditionBoundName);
 
   return forStmt(unless(isInTemplateInstantiation()),
@@ -168,7 +168,7 @@ static StatementMatcher makeIteratorLoopMatcher(bool 
IsReverse) {
   auto EndNameMatcherStd = IsReverse ? hasAnyName("::std::rend", 
"::std::crend")
                                      : hasAnyName("::std::end", "::std::cend");
 
-  StatementMatcher BeginCallMatcher =
+  const StatementMatcher BeginCallMatcher =
       expr(anyOf(cxxMemberCallExpr(argumentCountIs(0),
                                    callee(cxxMethodDecl(BeginNameMatcher))),
                  callExpr(argumentCountIs(1),
@@ -177,37 +177,37 @@ static StatementMatcher makeIteratorLoopMatcher(bool 
IsReverse) {
                           callee(functionDecl(BeginNameMatcherStd)))))
           .bind(BeginCallName);
 
-  DeclarationMatcher InitDeclMatcher =
+  const DeclarationMatcher InitDeclMatcher =
       varDecl(hasInitializer(anyOf(ignoringParenImpCasts(BeginCallMatcher),
                                    materializeTemporaryExpr(
                                        
ignoringParenImpCasts(BeginCallMatcher)),
                                    hasDescendant(BeginCallMatcher))))
           .bind(InitVarName);
 
-  DeclarationMatcher EndDeclMatcher =
+  const DeclarationMatcher EndDeclMatcher =
       varDecl(hasInitializer(anything())).bind(EndVarName);
 
-  StatementMatcher EndCallMatcher = expr(anyOf(
+  const StatementMatcher EndCallMatcher = expr(anyOf(
       cxxMemberCallExpr(argumentCountIs(0),
                         callee(cxxMethodDecl(EndNameMatcher))),
       callExpr(argumentCountIs(1), callee(functionDecl(EndNameMatcher)),
                usesADL()),
       callExpr(argumentCountIs(1), callee(functionDecl(EndNameMatcherStd)))));
 
-  StatementMatcher IteratorBoundMatcher =
+  const StatementMatcher IteratorBoundMatcher =
       expr(anyOf(ignoringParenImpCasts(
                      declRefExpr(to(varDecl(equalsBoundNode(EndVarName))))),
                  ignoringParenImpCasts(expr(EndCallMatcher).bind(EndCallName)),
                  materializeTemporaryExpr(ignoringParenImpCasts(
                      expr(EndCallMatcher).bind(EndCallName)))));
 
-  StatementMatcher IteratorComparisonMatcher = expr(ignoringParenImpCasts(
+  const StatementMatcher IteratorComparisonMatcher = 
expr(ignoringParenImpCasts(
       declRefExpr(to(varDecl(equalsBoundNode(InitVarName))))));
 
   // This matcher tests that a declaration is a CXXRecordDecl that has an
   // overloaded operator*(). If the operator*() returns by value instead of by
   // reference then the return type is tagged with DerefByValueResultName.
-  internal::Matcher<VarDecl> TestDerefReturnsByValue =
+  const internal::Matcher<VarDecl> TestDerefReturnsByValue =
       hasType(hasUnqualifiedDesugaredType(
           recordType(hasDeclaration(cxxRecordDecl(hasMethod(cxxMethodDecl(
               hasOverloadedOperatorName("*"),
@@ -280,7 +280,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
   // FIXME: Also, a record doesn't necessarily need begin() and end(). Free
   // functions called begin() and end() taking the container as an argument
   // are also allowed.
-  TypeMatcher RecordWithBeginEnd = qualType(anyOf(
+  const TypeMatcher RecordWithBeginEnd = qualType(anyOf(
       qualType(isConstQualified(),
                hasUnqualifiedDesugaredType(recordType(hasDeclaration(
                    cxxRecordDecl(isSameOrDerivedFrom(cxxRecordDecl(
@@ -295,7 +295,7 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
                        hasMethod(hasName("end"))))))))) // qualType
       ));
 
-  StatementMatcher SizeCallMatcher = expr(anyOf(
+  const StatementMatcher SizeCallMatcher = expr(anyOf(
       cxxMemberCallExpr(argumentCountIs(0),
                         callee(cxxMethodDecl(hasAnyName("size", "length"))),
                         on(anyOf(hasType(pointsTo(RecordWithBeginEnd)),
@@ -310,10 +310,10 @@ static StatementMatcher makePseudoArrayLoopMatcher() {
                  explicitCastExpr(hasSourceExpression(ignoringParenImpCasts(
                      expr(SizeCallMatcher).bind(EndCallName))))));
 
-  DeclarationMatcher EndDeclMatcher =
+  const DeclarationMatcher EndDeclMatcher =
       varDecl(hasInitializer(EndInitMatcher)).bind(EndVarName);
 
-  StatementMatcher IndexBoundMatcher =
+  const StatementMatcher IndexBoundMatcher =
       expr(anyOf(ignoringParenImpCasts(
                      declRefExpr(to(varDecl(equalsBoundNode(EndVarName))))),
                  EndInitMatcher));
@@ -620,7 +620,7 @@ void LoopConvertCheck::getAliasRange(SourceManager &SM, 
SourceRange &Range) {
       SM.getCharacterData(Range.getEnd().getLocWithOffset(1), &Invalid);
   if (Invalid)
     return;
-  unsigned Offset = std::strspn(TextAfter, " \t\r\n");
+  const unsigned Offset = std::strspn(TextAfter, " \t\r\n");
   Range =
       SourceRange(Range.getBegin(), Range.getEnd().getLocWithOffset(Offset));
 }
@@ -633,7 +633,7 @@ void LoopConvertCheck::doConversion(
     const DeclStmt *AliasDecl, bool AliasUseRequired, bool AliasFromForInit,
     const ForStmt *Loop, RangeDescriptor Descriptor) {
   std::string VarNameOrStructuredBinding;
-  bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
+  const bool VarNameFromAlias = (Usages.size() == 1) && AliasDecl;
   bool AliasVarIsRef = false;
   bool CanCopy = true;
   std::vector<FixItHint> FixIts;
@@ -743,7 +743,7 @@ void LoopConvertCheck::doConversion(
   }
 
   // Now, we need to construct the new range expression.
-  SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
+  const SourceRange ParenRange(Loop->getLParenLoc(), Loop->getRParenLoc());
 
   QualType Type = Context->getAutoDeductType();
   if (!Descriptor.ElemType.isNull() && 
Descriptor.ElemType->isFundamentalType())
@@ -753,14 +753,15 @@ void LoopConvertCheck::doConversion(
   // If the new variable name is from the aliased variable, then the reference
   // type for the new variable should only be used if the aliased variable was
   // declared as a reference.
-  bool IsCheapToCopy =
+  const bool IsCheapToCopy =
       !Descriptor.ElemType.isNull() &&
       Descriptor.ElemType.isTriviallyCopyableType(*Context) &&
       !Descriptor.ElemType->isDependentSizedArrayType() &&
       // TypeInfo::Width is in bits.
       Context->getTypeInfo(Descriptor.ElemType).Width <= 8 * MaxCopySize;
-  bool UseCopy = CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
-                             (Descriptor.DerefByConstRef && IsCheapToCopy));
+  const bool UseCopy =
+      CanCopy && ((VarNameFromAlias && !AliasVarIsRef) ||
+                  (Descriptor.DerefByConstRef && IsCheapToCopy));
 
   if (!UseCopy) {
     if (Descriptor.DerefByConstRef) {
@@ -866,7 +867,7 @@ void LoopConvertCheck::getIteratorLoopQualifiers(ASTContext 
*Context,
   // The matchers for iterator loops provide bound nodes to obtain this
   // information.
   const auto *InitVar = Nodes.getNodeAs<VarDecl>(InitVarName);
-  QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
+  const QualType CanonicalInitVarType = InitVar->getType().getCanonicalType();
   const auto *DerefByValueType =
       Nodes.getNodeAs<QualType>(DerefByValueResultName);
   Descriptor.DerefByValue = DerefByValueType;
@@ -934,12 +935,12 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
 
   // FIXME: Try to put most of this logic inside a matcher.
   if (FixerKind == LFK_Iterator || FixerKind == LFK_ReverseIterator) {
-    QualType InitVarType = InitVar->getType();
-    QualType CanonicalInitVarType = InitVarType.getCanonicalType();
+    const QualType InitVarType = InitVar->getType();
+    const QualType CanonicalInitVarType = InitVarType.getCanonicalType();
 
     const auto *BeginCall = Nodes.getNodeAs<CallExpr>(BeginCallName);
     assert(BeginCall && "Bad Callback. No begin call expression");
-    QualType CanonicalBeginType =
+    const QualType CanonicalBeginType =
         BeginCall->getDirectCallee()->getReturnType().getCanonicalType();
     if (CanonicalBeginType->isPointerType() &&
         CanonicalInitVarType->isPointerType()) {
@@ -1054,7 +1055,7 @@ void LoopConvertCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 
   // Find out which qualifiers we have to use in the loop range.
-  TraversalKindScope RAII(*Context, TK_AsIs);
+  const TraversalKindScope RAII(*Context, TK_AsIs);
   const UsageResult &Usages = Finder.getUsages();
   determineRangeDescriptor(Context, Nodes, Loop, FixerKind, ContainerExpr,
                            Usages, Descriptor);
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp 
b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 6fb780844f2b6..170a4f6d8731f 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -101,7 +101,8 @@ bool DependencyFinderASTVisitor::VisitVarDecl(VarDecl *V) {
 /// If we already created a variable for TheLoop, check to make sure
 /// that the name was not already taken.
 bool DeclFinderASTVisitor::VisitForStmt(ForStmt *TheLoop) {
-  StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(TheLoop);
+  const StmtGeneratedVarNameMap::const_iterator I =
+      GeneratedDecls->find(TheLoop);
   if (I != GeneratedDecls->end() && I->second == Name) {
     Found = true;
     return false;
@@ -131,7 +132,7 @@ bool DeclFinderASTVisitor::VisitDeclRefExpr(DeclRefExpr 
*DeclRef) {
 /// If the new variable name conflicts with any type used in the loop,
 /// then we mark that variable name as taken.
 bool DeclFinderASTVisitor::VisitTypeLoc(TypeLoc TL) {
-  QualType QType = TL.getType();
+  const QualType QType = TL.getType();
 
   // Check if our name conflicts with a type, to handle for typedefs.
   if (QType.getAsString() == Name) {
@@ -364,7 +365,7 @@ static bool isAliasDecl(ASTContext *Context, const Decl 
*TheDecl,
   // Check that the declared type is the same as (or a reference to) the
   // container type.
   if (!OnlyCasts) {
-    QualType InitType = Init->getType();
+    const QualType InitType = Init->getType();
     QualType DeclarationType = VDecl->getType();
     if (!DeclarationType.isNull() && DeclarationType->isReferenceType())
       DeclarationType = DeclarationType.getNonReferenceType();
@@ -440,7 +441,7 @@ static bool arrayMatchesBoundExpr(ASTContext *Context,
       ConditionExpr->getIntegerConstantExpr(*Context);
   if (!ConditionSize)
     return false;
-  llvm::APSInt ArraySize(ConstType->getSize());
+  const llvm::APSInt ArraySize(ConstType->getSize());
   return llvm::APSInt::isSameValue(*ConditionSize, ArraySize);
 }
 
@@ -571,7 +572,7 @@ bool ForLoopIndexUseVisitor::TraverseMemberExpr(MemberExpr 
*Member) {
 
     // FIXME: This works around not having the location of the arrow operator.
     // Consider adding OperatorLoc to MemberExpr?
-    SourceLocation ArrowLoc = Lexer::getLocForEndOfToken(
+    const SourceLocation ArrowLoc = Lexer::getLocForEndOfToken(
         Base->getExprLoc(), 0, Context->getSourceManager(),
         Context->getLangOpts());
     // If something complicated is happening (i.e. the next token isn't an
@@ -821,7 +822,7 @@ bool ForLoopIndexUseVisitor::traverseStmtImpl(Stmt *S) {
   const Stmt *OldNextParent = NextStmtParent;
   CurrStmtParent = NextStmtParent;
   NextStmtParent = S;
-  bool Result = VisitorBase::TraverseStmt(S);
+  const bool Result = VisitorBase::TraverseStmt(S);
   NextStmtParent = OldNextParent;
   return Result;
 }
@@ -850,7 +851,7 @@ std::string VariableNamer::createIndexName() {
   if (TheContainer)
     ContainerName = TheContainer->getName();
 
-  size_t Len = ContainerName.size();
+  const size_t Len = ContainerName.size();
   if (Len > 1 && ContainerName.ends_with(Style == NS_UpperCase ? "S" : "s")) {
     IteratorName = std::string(ContainerName.substr(0, Len - 1));
     // E.g.: (auto thing : things)
@@ -876,7 +877,7 @@ std::string VariableNamer::createIndexName() {
 /// converter in a loop nested within SourceStmt.
 bool VariableNamer::declarationExists(StringRef Symbol) {
   assert(Context != nullptr && "Expected an ASTContext");
-  IdentifierInfo &Ident = Context->Idents.get(Symbol);
+  const IdentifierInfo &Ident = Context->Idents.get(Symbol);
 
   // Check if the symbol is not an identifier (ie. is a keyword or alias).
   if (!isAnyIdentifier(Ident.getTokenID()))
@@ -888,7 +889,7 @@ bool VariableNamer::declarationExists(StringRef Symbol) {
 
   // Determine if the symbol was generated in a parent context.
   for (const Stmt *S = SourceStmt; S != nullptr; S = ReverseAST->lookup(S)) {
-    StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(S);
+    const StmtGeneratedVarNameMap::const_iterator I = GeneratedDecls->find(S);
     if (I != GeneratedDecls->end() && I->second == Symbol)
       return true;
   }
diff --git a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
index 2669aa2361ea1..098d46cae5df4 100644
--- a/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MacroToEnumCheck.cpp
@@ -23,7 +23,7 @@ static bool hasOnlyComments(SourceLocation Loc, const 
LangOptions &Options,
                             StringRef Text) {
   // Use a lexer to look for tokens; if we find something other than a single
   // hash, then there were intervening tokens between macro definitions.
-  std::string Buffer{Text};
+  const std::string Buffer{Text};
   Lexer Lex(Loc, Options, Buffer.c_str(), Buffer.c_str(),
             Buffer.c_str() + Buffer.size());
   Token Tok;
@@ -47,7 +47,7 @@ static bool hasOnlyComments(SourceLocation Loc, const 
LangOptions &Options,
   };
 
   WhiteSpace State = WhiteSpace::Nothing;
-  for (char C : Text) {
+  for (const char C : Text) {
     switch (C) {
     case '\r':
       if (State == WhiteSpace::CR)
@@ -227,17 +227,17 @@ bool MacroToEnumCallbacks::isConsecutiveMacro(const 
MacroDirective *MD) const {
   if (CurrentFile->LastMacroLocation.isInvalid())
     return false;
 
-  SourceLocation Loc = MD->getLocation();
+  const SourceLocation Loc = MD->getLocation();
   if (CurrentFile->LastLine + 1 == SM.getSpellingLineNumber(Loc))
     return true;
 
-  SourceLocation Define =
+  const SourceLocation Define =
       SM.translateLineCol(SM.getFileID(Loc), SM.getSpellingLineNumber(Loc), 1);
-  CharSourceRange BetweenMacros{
+  const CharSourceRange BetweenMacros{
       SourceRange{CurrentFile->LastMacroLocation, Define}, true};
-  CharSourceRange CharRange =
+  const CharSourceRange CharRange =
       Lexer::makeFileCharRange(BetweenMacros, SM, LangOpts);
-  StringRef BetweenText = Lexer::getSourceText(CharRange, SM, LangOpts);
+  const StringRef BetweenText = Lexer::getSourceText(CharRange, SM, LangOpts);
   return hasOnlyComments(Define, LangOpts, BetweenText);
 }
 
@@ -258,7 +258,7 @@ void MacroToEnumCallbacks::conditionStart(const 
SourceLocation &Loc) {
 }
 
 void MacroToEnumCallbacks::checkCondition(SourceRange Range) {
-  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  const CharSourceRange CharRange = Lexer::makeFileCharRange(
       CharSourceRange::getTokenRange(Range), SM, LangOpts);
   std::string Text = Lexer::getSourceText(CharRange, SM, LangOpts).str();
   Lexer Lex(CharRange.getBegin(), LangOpts, Text.data(), Text.data(),
@@ -285,7 +285,7 @@ void MacroToEnumCallbacks::checkName(const Token 
&MacroNameTok) {
 }
 
 void MacroToEnumCallbacks::rememberExpressionName(const Token &Tok) {
-  std::string Id = getTokenName(Tok).str();
+  const std::string Id = getTokenName(Tok).str();
   auto Pos = llvm::lower_bound(ExpressionNames, Id);
   if (Pos == ExpressionNames.end() || *Pos != Id) {
     ExpressionNames.insert(Pos, Id);
@@ -294,7 +294,7 @@ void MacroToEnumCallbacks::rememberExpressionName(const 
Token &Tok) {
 
 void MacroToEnumCallbacks::rememberExpressionTokens(
     ArrayRef<Token> MacroTokens) {
-  for (Token Tok : MacroTokens) {
+  for (const Token Tok : MacroTokens) {
     if (Tok.isAnyIdentifier())
       rememberExpressionName(Tok);
   }
@@ -318,8 +318,8 @@ void MacroToEnumCallbacks::FileChanged(SourceLocation Loc,
 
 bool MacroToEnumCallbacks::isInitializer(ArrayRef<Token> MacroTokens) {
   IntegralLiteralExpressionMatcher Matcher(MacroTokens, LangOpts.C99 == 0);
-  bool Matched = Matcher.match();
-  bool IsC = !LangOpts.CPlusPlus;
+  const bool Matched = Matcher.match();
+  const bool IsC = !LangOpts.CPlusPlus;
   if (IsC && (Matcher.largestLiteralSize() != LiteralSize::Int &&
               Matcher.largestLiteralSize() != LiteralSize::UnsignedInt))
     return false;
@@ -344,7 +344,7 @@ void MacroToEnumCallbacks::MacroDefined(const Token 
&MacroNameTok,
     return;
 
   const MacroInfo *Info = MD->getMacroInfo();
-  ArrayRef<Token> MacroTokens = Info->tokens();
+  const ArrayRef<Token> MacroTokens = Info->tokens();
   if (Info->isBuiltinMacro() || MacroTokens.empty())
     return;
   if (Info->isFunctionLike()) {
@@ -474,26 +474,26 @@ void MacroToEnumCallbacks::fixEnumMacro(const MacroList 
&MacroList) const {
       MacroList.front().Directive->getMacroInfo()->getDefinitionLoc();
   Begin = SM.translateLineCol(SM.getFileID(Begin),
                               SM.getSpellingLineNumber(Begin), 1);
-  DiagnosticBuilder Diagnostic =
+  const DiagnosticBuilder Diagnostic =
       Check->diag(Begin, "replace macro with enum")
       << FixItHint::CreateInsertion(Begin, "enum {\n");
 
   for (size_t I = 0U; I < MacroList.size(); ++I) {
     const EnumMacro &Macro = MacroList[I];
-    SourceLocation DefineEnd =
+    const SourceLocation DefineEnd =
         Macro.Directive->getMacroInfo()->getDefinitionLoc();
-    SourceLocation DefineBegin = SM.translateLineCol(
+    const SourceLocation DefineBegin = SM.translateLineCol(
         SM.getFileID(DefineEnd), SM.getSpellingLineNumber(DefineEnd), 1);
     CharSourceRange DefineRange;
     DefineRange.setBegin(DefineBegin);
     DefineRange.setEnd(DefineEnd);
     Diagnostic << FixItHint::CreateRemoval(DefineRange);
 
-    SourceLocation NameEnd = Lexer::getLocForEndOfToken(
+    const SourceLocation NameEnd = Lexer::getLocForEndOfToken(
         Macro.Directive->getMacroInfo()->getDefinitionLoc(), 0, SM, LangOpts);
     Diagnostic << FixItHint::CreateInsertion(NameEnd, " =");
 
-    SourceLocation ValueEnd = Lexer::getLocForEndOfToken(
+    const SourceLocation ValueEnd = Lexer::getLocForEndOfToken(
         Macro.Directive->getMacroInfo()->getDefinitionEndLoc(), 0, SM,
         LangOpts);
     if (I < MacroList.size() - 1)
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index 9d01e27fbab9c..7940939eb21a5 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -24,7 +24,7 @@ static constexpr char NewExpression[] = "newExpression";
 static std::string getNewExprName(const CXXNewExpr *NewExpr,
                                   const SourceManager &SM,
                                   const LangOptions &Lang) {
-  StringRef WrittenName = Lexer::getSourceText(
+  const StringRef WrittenName = Lexer::getSourceText(
       CharSourceRange::getTokenRange(
           
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
       SM, Lang);
@@ -134,9 +134,9 @@ void MakeSmartPtrCheck::check(const 
MatchFinder::MatchResult &Result) {
   //
   // The fix of the check has side effect, it introduces value initialization
   // which maybe unexpected and cause performance regression.
-  bool Initializes = New->hasInitializer() ||
-                     !utils::type_traits::isTriviallyDefaultConstructible(
-                         New->getAllocatedType(), *Result.Context);
+  const bool Initializes = New->hasInitializer() ||
+                           
!utils::type_traits::isTriviallyDefaultConstructible(
+                               New->getAllocatedType(), *Result.Context);
   if (!Initializes && IgnoreDefaultInitialization)
     return;
   if (Construct)
@@ -150,15 +150,15 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, 
ASTContext *Ctx,
                                        const VarDecl *DVar,
                                        const QualType *Type,
                                        const CXXNewExpr *New) {
-  SourceLocation ConstructCallStart = Construct->getExprLoc();
-  bool InMacro = ConstructCallStart.isMacroID();
+  const SourceLocation ConstructCallStart = Construct->getExprLoc();
+  const bool InMacro = ConstructCallStart.isMacroID();
 
   if (InMacro && IgnoreMacros) {
     return;
   }
 
   bool Invalid = false;
-  StringRef ExprStr = Lexer::getSourceText(
+  const StringRef ExprStr = Lexer::getSourceText(
       CharSourceRange::getCharRange(
           ConstructCallStart, Construct->getParenOrBraceRange().getBegin()),
       SM, getLangOpts(), &Invalid);
@@ -178,7 +178,7 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, 
ASTContext *Ctx,
   }
 
   // Find the location of the template's left angle.
-  size_t LAngle = ExprStr.find('<');
+  const size_t LAngle = ExprStr.find('<');
   SourceLocation ConstructCallEnd;
   if (LAngle == StringRef::npos) {
     // If the template argument is missing (because it is part of the alias)
@@ -202,7 +202,7 @@ void MakeSmartPtrCheck::checkConstruct(SourceManager &SM, 
ASTContext *Ctx,
   // If the smart_ptr is built with brace enclosed direct initialization, use
   // parenthesis instead.
   if (Construct->isListInitialization()) {
-    SourceRange BraceRange = Construct->getParenOrBraceRange();
+    const SourceRange BraceRange = Construct->getParenOrBraceRange();
     Diag << FixItHint::CreateReplacement(
         CharSourceRange::getCharRange(
             BraceRange.getBegin(), BraceRange.getBegin().getLocWithOffset(1)),
@@ -220,13 +220,13 @@ void MakeSmartPtrCheck::checkReset(SourceManager &SM, 
ASTContext *Ctx,
                                    const CXXMemberCallExpr *Reset,
                                    const CXXNewExpr *New) {
   const auto *Expr = cast<MemberExpr>(Reset->getCallee());
-  SourceLocation OperatorLoc = Expr->getOperatorLoc();
-  SourceLocation ResetCallStart = Reset->getExprLoc();
-  SourceLocation ExprStart = Expr->getBeginLoc();
-  SourceLocation ExprEnd =
+  const SourceLocation OperatorLoc = Expr->getOperatorLoc();
+  const SourceLocation ResetCallStart = Reset->getExprLoc();
+  const SourceLocation ExprStart = Expr->getBeginLoc();
+  const SourceLocation ExprEnd =
       Lexer::getLocForEndOfToken(Expr->getEndLoc(), 0, SM, getLangOpts());
 
-  bool InMacro = ExprStart.isMacroID();
+  const bool InMacro = ExprStart.isMacroID();
 
   if (InMacro && IgnoreMacros) {
     return;
@@ -267,7 +267,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
                                    const CXXNewExpr *New, SourceManager &SM,
                                    ASTContext *Ctx) {
   auto SkipParensParents = [&](const Expr *E) {
-    TraversalKindScope RAII(*Ctx, TK_AsIs);
+    const TraversalKindScope RAII(*Ctx, TK_AsIs);
 
     for (const Expr *OldE = nullptr; E != OldE;) {
       OldE = E;
@@ -281,9 +281,9 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
     return E;
   };
 
-  SourceRange NewRange = SkipParensParents(New)->getSourceRange();
-  SourceLocation NewStart = NewRange.getBegin();
-  SourceLocation NewEnd = NewRange.getEnd();
+  const SourceRange NewRange = SkipParensParents(New)->getSourceRange();
+  const SourceLocation NewStart = NewRange.getBegin();
+  const SourceLocation NewEnd = NewRange.getEnd();
 
   // Skip when the source location of the new expression is invalid.
   if (NewStart.isInvalid() || NewEnd.isInvalid())
@@ -362,7 +362,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
         return false;
     }
     if (ArraySizeExpr.empty()) {
-      SourceRange InitRange = New->getDirectInitRange();
+      const SourceRange InitRange = New->getDirectInitRange();
       Diag << FixItHint::CreateRemoval(
           SourceRange(NewStart, InitRange.getBegin()));
       Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), 
NewEnd));
diff --git a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
index d5ccbb73735ec..a257f5325f780 100644
--- a/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/PassByValueCheck.cpp
@@ -24,7 +24,8 @@ static bool isFirstFriendOfSecond(const CXXRecordDecl *Friend,
                                   const CXXRecordDecl *Class) {
   return llvm::any_of(
       Class->friends(), [Friend](FriendDecl *FriendDecl) -> bool {
-        if (TypeSourceInfo *FriendTypeSource = FriendDecl->getFriendType()) {
+        if (const TypeSourceInfo *FriendTypeSource =
+                FriendDecl->getFriendType()) {
           const QualType FriendType = FriendTypeSource->getType();
           return FriendType->getAsCXXRecordDecl() == Friend;
         }
@@ -208,7 +209,7 @@ static SmallVector<const ParmVarDecl *, 2>
 collectParamDecls(const CXXConstructorDecl *Ctor,
                   const ParmVarDecl *ParamDecl) {
   SmallVector<const ParmVarDecl *, 2> Results;
-  unsigned ParamIdx = ParamDecl->getFunctionScopeIndex();
+  const unsigned ParamIdx = ParamDecl->getFunctionScopeIndex();
 
   for (const FunctionDecl *Redecl : Ctor->redecls())
     Results.push_back(Redecl->getParamDecl(ParamIdx));
@@ -275,7 +276,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult 
&Result) {
   const auto *ParamDecl = Result.Nodes.getNodeAs<ParmVarDecl>("Param");
   const auto *Initializer =
       Result.Nodes.getNodeAs<CXXCtorInitializer>("Initializer");
-  SourceManager &SM = *Result.SourceManager;
+  const SourceManager &SM = *Result.SourceManager;
 
   // If the parameter is used or anything other than the copy, do not apply
   // the changes.
@@ -299,7 +300,7 @@ void PassByValueCheck::check(const MatchFinder::MatchResult 
&Result) {
   if (ParamDecl->getType()->isLValueReferenceType()) {
     // Check if we can succesfully rewrite all declarations of the constructor.
     for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
-      TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
+      const TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
       auto RefTL = ParamTL.getAs<ReferenceTypeLoc>();
       if (RefTL.isNull()) {
         // We cannot rewrite this instance. The type is probably hidden behind
@@ -309,11 +310,11 @@ void PassByValueCheck::check(const 
MatchFinder::MatchResult &Result) {
     }
     // Rewrite all declarations.
     for (const ParmVarDecl *ParmDecl : collectParamDecls(Ctor, ParamDecl)) {
-      TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
+      const TypeLoc ParamTL = ParmDecl->getTypeSourceInfo()->getTypeLoc();
       auto RefTL = ParamTL.getAs<ReferenceTypeLoc>();
 
-      TypeLoc ValueTL = RefTL.getPointeeLoc();
-      CharSourceRange TypeRange = CharSourceRange::getTokenRange(
+      const TypeLoc ValueTL = RefTL.getPointeeLoc();
+      const CharSourceRange TypeRange = CharSourceRange::getTokenRange(
           ParmDecl->getBeginLoc(), ParamTL.getEndLoc());
       std::string ValueStr =
           Lexer::getSourceText(
diff --git a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
index 8e514e4bc9893..2c4bddf262721 100644
--- a/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
@@ -51,11 +51,11 @@ static bool containsEscapedCharacters(const 
MatchFinder::MatchResult &Result,
     if (DisallowedChars.test(C))
       return false;
 
-  CharSourceRange CharRange = Lexer::makeFileCharRange(
+  const CharSourceRange CharRange = Lexer::makeFileCharRange(
       CharSourceRange::getTokenRange(Literal->getSourceRange()),
       *Result.SourceManager, Result.Context->getLangOpts());
-  StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
-                                        Result.Context->getLangOpts());
+  const StringRef Text = Lexer::getSourceText(CharRange, *Result.SourceManager,
+                                              Result.Context->getLangOpts());
   if (Text.empty() || isRawStringLiteral(Text))
     return false;
 
@@ -116,7 +116,7 @@ createUserDefinedSuffix(const StringLiteral *Literal, const 
SourceManager &SM,
   const CharSourceRange CharRange =
       Lexer::makeFileCharRange(TokenRange, SM, LangOpts);
   if (T.hasUDSuffix()) {
-    StringRef Text = Lexer::getSourceText(CharRange, SM, LangOpts);
+    const StringRef Text = Lexer::getSourceText(CharRange, SM, LangOpts);
     const size_t UDSuffixPos = Text.find_last_of('"');
     if (UDSuffixPos == StringRef::npos)
       return std::nullopt;
@@ -135,7 +135,7 @@ static std::string createRawStringLiteral(const 
StringLiteral *Literal,
     Delimiter = (I == 0) ? DelimiterStem : DelimiterStem + std::to_string(I);
   }
 
-  std::optional<StringRef> UserDefinedSuffix =
+  const std::optional<StringRef> UserDefinedSuffix =
       createUserDefinedSuffix(Literal, SM, LangOpts);
 
   if (Delimiter.empty())
diff --git a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
index 38b30f7994ff3..aa2db2146475b 100644
--- a/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/RedundantVoidArgCheck.cpp
@@ -89,9 +89,9 @@ void RedundantVoidArgCheck::check(const 
MatchFinder::MatchResult &Result) {
 void RedundantVoidArgCheck::processFunctionDecl(
     const MatchFinder::MatchResult &Result, const FunctionDecl *Function) {
   const auto *Method = dyn_cast<CXXMethodDecl>(Function);
-  SourceLocation Start = Method && Method->getParent()->isLambda()
-                             ? Method->getBeginLoc()
-                             : Function->getLocation();
+  const SourceLocation Start = Method && Method->getParent()->isLambda()
+                                   ? Method->getBeginLoc()
+                                   : Function->getLocation();
   SourceLocation End = Function->getEndLoc();
   if (Function->isThisDeclarationADefinition()) {
     if (const Stmt *Body = Function->getBody()) {
@@ -113,7 +113,8 @@ static bool isMacroIdentifier(const IdentifierTable &Idents,
   if (!ProtoToken.is(tok::TokenKind::raw_identifier))
     return false;
 
-  IdentifierTable::iterator It = Idents.find(ProtoToken.getRawIdentifier());
+  const IdentifierTable::iterator It =
+      Idents.find(ProtoToken.getRawIdentifier());
   if (It == Idents.end())
     return false;
 
@@ -123,7 +124,7 @@ static bool isMacroIdentifier(const IdentifierTable &Idents,
 void RedundantVoidArgCheck::removeVoidArgumentTokens(
     const ast_matchers::MatchFinder::MatchResult &Result, SourceRange Range,
     StringRef GrammarLocation) {
-  CharSourceRange CharRange =
+  const CharSourceRange CharRange =
       Lexer::makeFileCharRange(CharSourceRange::getTokenRange(Range),
                                *Result.SourceManager, getLangOpts());
 
@@ -145,7 +146,7 @@ void RedundantVoidArgCheck::removeVoidArgumentTokens(
   Token ProtoToken;
   const IdentifierTable &Idents = Result.Context->Idents;
   int MacroLevel = 0;
-  std::string Diagnostic =
+  const std::string Diagnostic =
       ("redundant void argument list in " + GrammarLocation).str();
 
   while (!PrototypeLexer.LexFromRawLexer(ProtoToken)) {
@@ -216,7 +217,7 @@ void RedundantVoidArgCheck::removeVoidArgumentTokens(
 
 void RedundantVoidArgCheck::removeVoidToken(Token VoidToken,
                                             StringRef Diagnostic) {
-  SourceLocation VoidLoc = VoidToken.getLocation();
+  const SourceLocation VoidLoc = VoidToken.getLocation();
   diag(VoidLoc, Diagnostic) << FixItHint::CreateRemoval(VoidLoc);
 }
 
@@ -239,9 +240,9 @@ void RedundantVoidArgCheck::processFieldDecl(
 void RedundantVoidArgCheck::processVarDecl(
     const MatchFinder::MatchResult &Result, const VarDecl *Var) {
   if (protoTypeHasNoParms(Var->getType())) {
-    SourceLocation Begin = Var->getBeginLoc();
+    const SourceLocation Begin = Var->getBeginLoc();
     if (Var->hasInit()) {
-      SourceLocation InitStart =
+      const SourceLocation InitStart =
           Result.SourceManager->getExpansionLoc(Var->getInit()->getBeginLoc())
               .getLocWithOffset(-1);
       removeVoidArgumentTokens(Result, SourceRange(Begin, InitStart),
@@ -273,8 +274,9 @@ void RedundantVoidArgCheck::processLambdaExpr(
     const MatchFinder::MatchResult &Result, const LambdaExpr *Lambda) {
   if (Lambda->getLambdaClass()->getLambdaCallOperator()->getNumParams() == 0 &&
       Lambda->hasExplicitParameters()) {
-    SourceManager *SM = Result.SourceManager;
-    TypeLoc TL = Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
+    const SourceManager *SM = Result.SourceManager;
+    const TypeLoc TL =
+        Lambda->getLambdaClass()->getLambdaTypeInfo()->getTypeLoc();
     removeVoidArgumentTokens(Result,
                              {SM->getSpellingLoc(TL.getBeginLoc()),
                               SM->getSpellingLoc(TL.getEndLoc())},
diff --git a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
index b562ae85aa266..d0577aeccd2f1 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceAutoPtrCheck.cpp
@@ -96,10 +96,10 @@ void ReplaceAutoPtrCheck::registerPPCallbacks(const 
SourceManager &SM,
 }
 
 void ReplaceAutoPtrCheck::check(const MatchFinder::MatchResult &Result) {
-  SourceManager &SM = *Result.SourceManager;
+  const SourceManager &SM = *Result.SourceManager;
   if (const auto *E =
           Result.Nodes.getNodeAs<Expr>(AutoPtrOwnershipTransferId)) {
-    CharSourceRange Range = Lexer::makeFileCharRange(
+    const CharSourceRange Range = Lexer::makeFileCharRange(
         CharSourceRange::getTokenRange(E->getSourceRange()), SM, 
LangOptions());
 
     if (Range.isInvalid())
@@ -140,7 +140,8 @@ void ReplaceAutoPtrCheck::check(const 
MatchFinder::MatchResult &Result) {
       "auto_ptr")
     return;
 
-  SourceLocation EndLoc = AutoPtrLoc.getLocWithOffset(strlen("auto_ptr") - 1);
+  const SourceLocation EndLoc =
+      AutoPtrLoc.getLocWithOffset(strlen("auto_ptr") - 1);
   diag(AutoPtrLoc, "auto_ptr is deprecated, use unique_ptr instead")
       << FixItHint::CreateReplacement(SourceRange(AutoPtrLoc, EndLoc),
                                       "unique_ptr");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
 
b/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
index 64b0029fc0e37..be5e21dce3ba1 100644
--- 
a/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/modernize/ReplaceDisallowCopyAndAssignMacroCheck.cpp
@@ -26,7 +26,7 @@ class ReplaceDisallowCopyAndAssignMacroCallbacks : public 
PPCallbacks {
 
   void MacroExpands(const Token &MacroNameTok, const MacroDefinition &MD,
                     SourceRange Range, const MacroArgs *Args) override {
-    IdentifierInfo *Info = MacroNameTok.getIdentifierInfo();
+    const IdentifierInfo *Info = MacroNameTok.getIdentifierInfo();
     if (!Info || !Args || Args->getNumMacroArguments() != 1)
       return;
     if (Info->getName() != Check.getMacroName())
@@ -38,11 +38,11 @@ class ReplaceDisallowCopyAndAssignMacroCallbacks : public 
PPCallbacks {
       // For now we only support simple argument that don't need to be
       // pre-expanded.
       return;
-    clang::IdentifierInfo *ClassIdent = ClassNameTok->getIdentifierInfo();
+    const clang::IdentifierInfo *ClassIdent = 
ClassNameTok->getIdentifierInfo();
     if (!ClassIdent)
       return;
 
-    std::string Replacement = llvm::formatv(
+    const std::string Replacement = llvm::formatv(
         R"cpp({0}(const {0} &) = delete;
 const {0} &operator=(const {0} &) = delete{1})cpp",
         ClassIdent->getName(), shouldAppendSemi(Range) ? ";" : "");
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
index 3d7b3eae544b6..cfc546a06b40c 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReplaceRandomShuffleCheck.cpp
@@ -78,7 +78,7 @@ void ReplaceRandomShuffleCheck::check(const 
MatchFinder::MatchResult &Result) {
   }();
 
   std::string NewName = "shuffle";
-  StringRef ContainerText = Lexer::getSourceText(
+  const StringRef ContainerText = Lexer::getSourceText(
       CharSourceRange::getTokenRange(MatchedDecl->getSourceRange()),
       *Result.SourceManager, getLangOpts());
   if (ContainerText.starts_with("std::"))
diff --git 
a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
index eba2445c0aaea..15b64bc413be8 100644
--- a/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ReturnBracedInitListCheck.cpp
@@ -54,7 +54,7 @@ void ReturnBracedInitListCheck::check(const 
MatchFinder::MatchResult &Result) {
       Result.Nodes.getNodeAs<CXXConstructExpr>("ctor");
 
   // Don't make replacements in macro.
-  SourceLocation Loc = MatchedConstructExpr->getExprLoc();
+  const SourceLocation Loc = MatchedConstructExpr->getExprLoc();
   if (Loc.isMacroID())
     return;
 
@@ -88,7 +88,7 @@ void ReturnBracedInitListCheck::check(const 
MatchFinder::MatchResult &Result) {
   }
 
   // Range for constructor name and opening brace.
-  CharSourceRange CtorCallSourceRange = CharSourceRange::getTokenRange(
+  const CharSourceRange CtorCallSourceRange = CharSourceRange::getTokenRange(
       Loc, CallParensRange.getBegin().getLocWithOffset(-1));
 
   Diag << FixItHint::CreateRemoval(CtorCallSourceRange)
diff --git a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
index 6078013166d46..06982b8698e0c 100644
--- a/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/TypeTraitsCheck.cpp
@@ -286,7 +286,7 @@ void TypeTraitsCheck::check(const MatchFinder::MatchResult 
&Result) {
 
   if (const auto *TL = Result.Nodes.getNodeAs<TypedefTypeLoc>(Bind)) {
     const NestedNameSpecifierLoc QualLoc = TL->getQualifierLoc();
-    NestedNameSpecifier NNS = QualLoc.getNestedNameSpecifier();
+    const NestedNameSpecifier NNS = QualLoc.getNestedNameSpecifier();
     if (const auto *CTSD = 
dyn_cast_if_present<ClassTemplateSpecializationDecl>(
             NNS.getAsRecordDecl())) {
       if (isNamedDeclInStdTraitsSet(CTSD, TypeTraits))
@@ -304,7 +304,7 @@ void TypeTraitsCheck::check(const MatchFinder::MatchResult 
&Result) {
   }
 
   if (const auto *DNTL = Result.Nodes.getNodeAs<DependentNameTypeLoc>(Bind)) {
-    NestedNameSpecifierLoc QualLoc = DNTL->getQualifierLoc();
+    const NestedNameSpecifierLoc QualLoc = DNTL->getQualifierLoc();
     if (checkTemplatedDecl(QualLoc.getNestedNameSpecifier(), TypeTraits))
       EmitTypeWarning(QualLoc, DNTL->getEndLoc(),
                       DNTL->getElaboratedKeywordLoc());
diff --git a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
index 4e4817f2ec2e6..28d8f7572d32b 100644
--- a/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UnaryStaticAssertCheck.cpp
@@ -23,7 +23,7 @@ void UnaryStaticAssertCheck::check(const 
MatchFinder::MatchResult &Result) {
   const auto *AssertMessage =
       dyn_cast_if_present<StringLiteral>(MatchedDecl->getMessage());
 
-  SourceLocation Loc = MatchedDecl->getLocation();
+  const SourceLocation Loc = MatchedDecl->getLocation();
 
   if (!AssertMessage || AssertMessage->getLength() ||
       AssertMessage->getBeginLoc().isMacroID() || Loc.isMacroID())
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index 084349be7b609..977ade12e2c3a 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -101,7 +101,8 @@ AST_MATCHER_P(QualType, isSugarFor, Matcher<QualType>, 
SugarMatcher) {
     if (SugarMatcher.matches(QT, Finder, Builder))
       return true;
 
-    QualType NewQT = QT.getSingleStepDesugaredType(Finder->getASTContext());
+    const QualType NewQT =
+        QT.getSingleStepDesugaredType(Finder->getASTContext());
     if (NewQT == QT)
       return false;
     QT = NewQT;
@@ -147,18 +148,19 @@ static Matcher<NamedDecl> hasStdIteratorName() {
 /// recordDecl(hasStdContainerName()) matches \c vector and \c forward_list
 /// but not \c my_vec.
 static Matcher<NamedDecl> hasStdContainerName() {
-  static StringRef ContainerNames[] = {"array",         "deque",
-                                       "forward_list",  "list",
-                                       "vector",
+  static const StringRef ContainerNames[] = {
+      "array",         "deque",
+      "forward_list",  "list",
+      "vector",
 
-                                       "map",           "multimap",
-                                       "set",           "multiset",
+      "map",           "multimap",
+      "set",           "multiset",
 
-                                       "unordered_map", "unordered_multimap",
-                                       "unordered_set", "unordered_multiset",
+      "unordered_map", "unordered_multimap",
+      "unordered_set", "unordered_multiset",
 
-                                       "queue",         "priority_queue",
-                                       "stack"};
+      "queue",         "priority_queue",
+      "stack"};
 
   return hasAnyName(ContainerNames);
 }
@@ -326,7 +328,8 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, 
ASTContext *Context) {
   // like function pointers. Not a concern since this action only works with
   // iterators but something to keep in mind in the future.
 
-  SourceRange Range(V->getTypeSourceInfo()->getTypeLoc().getSourceRange());
+  const SourceRange Range(
+      V->getTypeSourceInfo()->getTypeLoc().getSourceRange());
   diag(Range.getBegin(), "use auto when declaring iterators")
       << FixItHint::CreateReplacement(Range, "auto");
 }
@@ -342,7 +345,7 @@ static bool isMultiLevelPointerToTypeLocClasses(
     TypeLoc Loc,
     const std::initializer_list<TypeLoc::TypeLocClass> &LocClasses) {
   ignoreTypeLocClasses(Loc, {TypeLoc::Paren, TypeLoc::Qualified});
-  TypeLoc::TypeLocClass TLC = Loc.getTypeLocClass();
+  const TypeLoc::TypeLocClass TLC = Loc.getTypeLocClass();
   if (TLC != TypeLoc::Pointer && TLC != TypeLoc::MemberPointer)
     return false;
   ignoreTypeLocClasses(Loc, {TypeLoc::Paren, TypeLoc::Qualified,
@@ -359,7 +362,7 @@ void UseAutoCheck::replaceExpr(
     return;
 
   const QualType FirstDeclType = FirstDecl->getType().getCanonicalType();
-  TypeSourceInfo *TSI = FirstDecl->getTypeSourceInfo();
+  const TypeSourceInfo *TSI = FirstDecl->getTypeSourceInfo();
 
   if (TSI == nullptr)
     return;
@@ -409,7 +412,7 @@ void UseAutoCheck::replaceExpr(
     ignoreTypeLocClasses(Loc, {TypeLoc::Pointer, TypeLoc::Qualified});
   ignoreTypeLocClasses(Loc, {TypeLoc::LValueReference, 
TypeLoc::RValueReference,
                              TypeLoc::Qualified});
-  SourceRange Range(Loc.getSourceRange());
+  const SourceRange Range(Loc.getSourceRange());
 
   if (MinTypeNameLength != 0 &&
       getTypeNameLength(RemoveStars,
@@ -420,17 +423,17 @@ void UseAutoCheck::replaceExpr(
 
   auto Diag = diag(Range.getBegin(), Message);
 
-  bool ShouldReplenishVariableName = isMultiLevelPointerToTypeLocClasses(
+  const bool ShouldReplenishVariableName = isMultiLevelPointerToTypeLocClasses(
       TSI->getTypeLoc(), {TypeLoc::FunctionProto, TypeLoc::ConstantArray});
 
   // Space after 'auto' to handle cases where the '*' in the pointer type is
   // next to the identifier. This avoids changing 'int *p' into 'autop'.
-  llvm::StringRef Auto = ShouldReplenishVariableName
-                             ? (RemoveStars ? "auto " : "auto *")
-                             : (RemoveStars ? "auto " : "auto");
-  std::string ReplenishedVariableName =
+  const llvm::StringRef Auto = ShouldReplenishVariableName
+                                   ? (RemoveStars ? "auto " : "auto *")
+                                   : (RemoveStars ? "auto " : "auto");
+  const std::string ReplenishedVariableName =
       ShouldReplenishVariableName ? FirstDecl->getQualifiedNameAsString() : "";
-  std::string Replacement =
+  const std::string Replacement =
       (Auto + llvm::StringRef{ReplenishedVariableName}).str();
   Diag << FixItHint::CreateReplacement(Range, Replacement) << StarRemovals;
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
index 8b5ffe86b1839..6e2118787f9b4 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
@@ -50,14 +50,14 @@ void UseBoolLiteralsCheck::registerMatchers(MatchFinder 
*Finder) {
 void UseBoolLiteralsCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Literal = Result.Nodes.getNodeAs<IntegerLiteral>("literal");
   const auto *Cast = Result.Nodes.getNodeAs<Expr>("cast");
-  bool LiteralBooleanValue = Literal->getValue().getBoolValue();
+  const bool LiteralBooleanValue = Literal->getValue().getBoolValue();
 
   if (Literal->isInstantiationDependent())
     return;
 
   const Expr *Expression = Cast ? Cast : Literal;
 
-  bool InMacro = Expression->getBeginLoc().isMacroID();
+  const bool InMacro = Expression->getBeginLoc().isMacroID();
 
   if (InMacro && IgnoreMacros)
     return;
diff --git a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
index d5342a1664153..fdb088fe44be2 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseConstraintsCheck.cpp
@@ -55,7 +55,7 @@ static std::optional<TemplateSpecializationTypeLoc>
 matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
   if (const auto Dep = TheType.getAs<DependentNameTypeLoc>()) {
     const IdentifierInfo *Identifier = Dep.getTypePtr()->getIdentifier();
-    ElaboratedTypeKeyword Keyword = Dep.getTypePtr()->getKeyword();
+    const ElaboratedTypeKeyword Keyword = Dep.getTypePtr()->getKeyword();
     if (!Identifier || Identifier->getName() != "type" ||
         (Keyword != ElaboratedTypeKeyword::Typename &&
          Keyword != ElaboratedTypeKeyword::None)) {
@@ -88,7 +88,7 @@ matchEnableIfSpecializationImplTypename(TypeLoc TheType) {
     if (!FirstParam || !FirstParam->getType()->isBooleanType())
       return std::nullopt;
 
-    int NumArgs = SpecializationLoc.getNumArgs();
+    const int NumArgs = SpecializationLoc.getNumArgs();
     if (NumArgs != 1 && NumArgs != 2)
       return std::nullopt;
 
@@ -124,7 +124,7 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
 
     if (const auto *AliasedType =
             dyn_cast<DependentNameType>(Specialization->getAliasedType())) {
-      ElaboratedTypeKeyword Keyword = AliasedType->getKeyword();
+      const ElaboratedTypeKeyword Keyword = AliasedType->getKeyword();
       if (AliasedType->getIdentifier()->getName() != "type" ||
           (Keyword != ElaboratedTypeKeyword::Typename &&
            Keyword != ElaboratedTypeKeyword::None)) {
@@ -133,7 +133,7 @@ matchEnableIfSpecializationImplTrait(TypeLoc TheType) {
     } else {
       return std::nullopt;
     }
-    int NumArgs = SpecializationLoc.getNumArgs();
+    const int NumArgs = SpecializationLoc.getNumArgs();
     if (NumArgs != 1 && NumArgs != 2)
       return std::nullopt;
 
@@ -223,7 +223,7 @@ getConditionRange(ASTContext &Context,
   const LangOptions &LangOpts = Context.getLangOpts();
   const SourceManager &SM = Context.getSourceManager();
   if (EnableIf.getNumArgs() > 1) {
-    TemplateArgumentLoc NextArg = EnableIf.getArgLoc(1);
+    const TemplateArgumentLoc NextArg = EnableIf.getArgLoc(1);
     return {EnableIf.getLAngleLoc().getLocWithOffset(1),
             utils::lexer::findPreviousTokenKind(
                 NextArg.getSourceRange().getBegin(), SM, LangOpts, 
tok::comma)};
@@ -235,7 +235,7 @@ getConditionRange(ASTContext &Context,
 
 static SourceRange getTypeRange(ASTContext &Context,
                                 const TemplateSpecializationTypeLoc &EnableIf) 
{
-  TemplateArgumentLoc Arg = EnableIf.getArgLoc(1);
+  const TemplateArgumentLoc Arg = EnableIf.getArgLoc(1);
   const LangOptions &LangOpts = Context.getLangOpts();
   const SourceManager &SM = Context.getSourceManager();
   return {utils::lexer::findPreviousTokenKind(Arg.getSourceRange().getBegin(),
@@ -269,7 +269,7 @@ getTypeText(ASTContext &Context,
 
 static std::optional<SourceLocation>
 findInsertionForConstraint(const FunctionDecl *Function, ASTContext &Context) {
-  SourceManager &SM = Context.getSourceManager();
+  const SourceManager &SM = Context.getSourceManager();
   const LangOptions &LangOpts = Context.getLangOpts();
 
   if (const auto *Constructor = dyn_cast<CXXConstructorDecl>(Function)) {
@@ -282,7 +282,7 @@ findInsertionForConstraint(const FunctionDecl *Function, 
ASTContext &Context) {
       return std::nullopt;
   }
   if (Function->isDeleted()) {
-    SourceLocation FunctionEnd = Function->getSourceRange().getEnd();
+    const SourceLocation FunctionEnd = Function->getSourceRange().getEnd();
     return utils::lexer::findNextAnyTokenKind(FunctionEnd, SM, LangOpts,
                                               tok::equal, tok::equal);
   }
@@ -314,7 +314,7 @@ static bool isPrimaryExpression(const Expr *Expression) {
 static std::optional<std::string> getConditionText(const Expr *ConditionExpr,
                                                    SourceRange ConditionRange,
                                                    ASTContext &Context) {
-  SourceManager &SM = Context.getSourceManager();
+  const SourceManager &SM = Context.getSourceManager();
   const LangOptions &LangOpts = Context.getLangOpts();
 
   SourceLocation PrevTokenLoc = ConditionRange.getEnd();
@@ -325,14 +325,14 @@ static std::optional<std::string> getConditionText(const 
Expr *ConditionExpr,
   Token PrevToken;
   std::tie(PrevToken, PrevTokenLoc) = utils::lexer::getPreviousTokenAndStart(
       PrevTokenLoc, SM, LangOpts, SkipComments);
-  bool EndsWithDoubleSlash =
+  const bool EndsWithDoubleSlash =
       PrevToken.is(tok::comment) &&
       Lexer::getSourceText(CharSourceRange::getCharRange(
                                PrevTokenLoc, PrevTokenLoc.getLocWithOffset(2)),
                            SM, LangOpts) == "//";
 
   bool Invalid = false;
-  llvm::StringRef ConditionText = Lexer::getSourceText(
+  const llvm::StringRef ConditionText = Lexer::getSourceText(
       CharSourceRange::getCharRange(ConditionRange), SM, LangOpts, &Invalid);
   if (Invalid)
     return std::nullopt;
@@ -361,9 +361,9 @@ static std::vector<FixItHint> handleReturnType(const 
FunctionDecl *Function,
                                                const TypeLoc &ReturnType,
                                                const EnableIfData &EnableIf,
                                                ASTContext &Context) {
-  TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
+  const TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
 
-  SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
+  const SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
 
   std::optional<std::string> ConditionText = getConditionText(
       EnableCondition.getSourceExpression(), ConditionRange, Context);
@@ -410,12 +410,12 @@ handleTrailingTemplateType(const FunctionTemplateDecl 
*FunctionTemplate,
                            const FunctionDecl *Function,
                            const Decl *LastTemplateParam,
                            const EnableIfData &EnableIf, ASTContext &Context) {
-  SourceManager &SM = Context.getSourceManager();
+  const SourceManager &SM = Context.getSourceManager();
   const LangOptions &LangOpts = Context.getLangOpts();
 
-  TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
+  const TemplateArgumentLoc EnableCondition = EnableIf.Loc.getArgLoc(0);
 
-  SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
+  const SourceRange ConditionRange = getConditionRange(Context, EnableIf.Loc);
 
   std::optional<std::string> ConditionText = getConditionText(
       EnableCondition.getSourceExpression(), ConditionRange, Context);

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to