[clang-tools-extra] [clang-tidy][NFC] Fix misc-const-correctness warnings (13/N) (PR #167130)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Nov 8 03:47:50 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-tools-extra
Author: Baranov Victor (vbvictor)
<details>
<summary>Changes</summary>
---
Patch is 43.69 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/167130.diff
19 Files Affected:
- (modified) clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp (+6-6)
- (modified) clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp (+2-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp (+3-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp (+3-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp (+20-20)
- (modified) clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp (+2-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp (+48-46)
- (modified) clang-tools-extra/clang-tidy/bugprone/PosixReturnCheck.cpp (+2-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/RedundantBranchConditionCheck.cpp (+5-5)
- (modified) clang-tools-extra/clang-tidy/bugprone/ReturnConstRefFromParameterCheck.cpp (+1-1)
- (modified) clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.cpp (+8-7)
- (modified) clang-tools-extra/clang-tidy/bugprone/SignalHandlerCheck.h (+3-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/SignedCharMisuseCheck.cpp (+2-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp (+3-3)
- (modified) clang-tools-extra/clang-tidy/bugprone/SmartPtrArrayMismatchCheck.cpp (+5-5)
- (modified) clang-tools-extra/clang-tidy/bugprone/SpuriouslyWakeUpFunctionsCheck.cpp (+1-1)
- (modified) clang-tools-extra/clang-tidy/bugprone/StandaloneEmptyCheck.cpp (+16-14)
- (modified) clang-tools-extra/clang-tidy/bugprone/StdNamespaceModificationCheck.cpp (+2-2)
- (modified) clang-tools-extra/clang-tidy/bugprone/StringConstructorCheck.cpp (+3-3)
``````````diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
index d508e2aaba53c..f040235322a4f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MisplacedWideningCastCheck.cpp
@@ -52,8 +52,8 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
E = E->IgnoreParenImpCasts();
if (const auto *Bop = dyn_cast<BinaryOperator>(E)) {
- unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
- unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
+ const unsigned LHSWidth = getMaxCalculationWidth(Context, Bop->getLHS());
+ const unsigned RHSWidth = getMaxCalculationWidth(Context, Bop->getRHS());
if (Bop->getOpcode() == BO_Mul)
return LHSWidth + RHSWidth;
if (Bop->getOpcode() == BO_Add)
@@ -79,7 +79,7 @@ static unsigned getMaxCalculationWidth(const ASTContext &Context,
if (Uop->getOpcode() == UO_Not)
return 1024U;
- QualType T = Uop->getType();
+ const QualType T = Uop->getType();
return T->isIntegerType() ? Context.getIntWidth(T) : 1024U;
} else if (const auto *I = dyn_cast<IntegerLiteral>(E)) {
return I->getValue().getActiveBits();
@@ -190,10 +190,10 @@ void MisplacedWideningCastCheck::check(const MatchFinder::MatchResult &Result) {
Calc->isTypeDependent() || Calc->isValueDependent())
return;
- ASTContext &Context = *Result.Context;
+ const ASTContext &Context = *Result.Context;
- QualType CastType = Cast->getType();
- QualType CalcType = Calc->getType();
+ const QualType CastType = Cast->getType();
+ const QualType CalcType = Calc->getType();
// Explicit truncation using cast.
if (Context.getIntWidth(CastType) < Context.getIntWidth(CalcType))
diff --git a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
index 66559a0e5d7b5..e182df75b1d9a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MoveForwardingReferenceCheck.cpp
@@ -21,7 +21,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
const SourceManager &SM = Context.getSourceManager();
const LangOptions &LangOpts = Context.getLangOpts();
- CharSourceRange CallRange =
+ const CharSourceRange CallRange =
Lexer::makeFileCharRange(CharSourceRange::getTokenRange(
Callee->getBeginLoc(), Callee->getEndLoc()),
SM, LangOpts);
@@ -39,7 +39,7 @@ static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
// std::move(). This will hopefully prevent erroneous replacements if the
// code does unusual things (e.g. create an alias for std::move() in
// another namespace).
- NestedNameSpecifier NNS = Callee->getQualifier();
+ const NestedNameSpecifier NNS = Callee->getQualifier();
switch (NNS.getKind()) {
case NestedNameSpecifier::Kind::Null:
// Called as "move" (i.e. presumably the code had a "using std::move;").
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
index 2eff013b2ab7d..78f2017984a96 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultiLevelImplicitPointerConversionCheck.cpp
@@ -86,8 +86,9 @@ MultiLevelImplicitPointerConversionCheck::getCheckTraversalKind() const {
void MultiLevelImplicitPointerConversionCheck::check(
const MatchFinder::MatchResult &Result) {
const auto *MatchedExpr = Result.Nodes.getNodeAs<ImplicitCastExpr>("expr");
- QualType Target = MatchedExpr->getType().getDesugaredType(*Result.Context);
- QualType Source =
+ const QualType Target =
+ MatchedExpr->getType().getDesugaredType(*Result.Context);
+ const QualType Source =
MatchedExpr->getSubExpr()->getType().getDesugaredType(*Result.Context);
diag(MatchedExpr->getExprLoc(), "multilevel pointer conversion from %0 to "
diff --git a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
index 17aea9392bd26..b81d2b438d58d 100644
--- a/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/MultipleNewInOneExpressionCheck.cpp
@@ -51,7 +51,8 @@ namespace {
AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
ast_matchers::internal::Matcher<QualType>, InnerMatcher) {
- for (unsigned NH = Node.getNumHandlers(), I = 0; I < NH; ++I) {
+ const unsigned NH = Node.getNumHandlers();
+ for (unsigned I = 0; I < NH; ++I) {
const CXXCatchStmt *CatchS = Node.getHandler(I);
// Check for generic catch handler (match anything).
if (CatchS->getCaughtType().isNull())
@@ -66,7 +67,7 @@ AST_MATCHER_P(CXXTryStmt, hasHandlerFor,
}
AST_MATCHER(CXXNewExpr, mayThrow) {
- FunctionDecl *OperatorNew = Node.getOperatorNew();
+ const FunctionDecl *OperatorNew = Node.getOperatorNew();
if (!OperatorNew)
return false;
return !OperatorNew->getType()->castAs<FunctionProtoType>()->isNothrow();
diff --git a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
index 287ee95a4db55..501a82d67d558 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NarrowingConversionsCheck.cpp
@@ -29,15 +29,15 @@ AST_MATCHER_P(QualType, hasAnyType, std::vector<StringRef>, Names) {
if (Names.empty())
return false;
- std::string Name = Node.getLocalUnqualifiedType().getAsString();
+ const std::string Name = Node.getLocalUnqualifiedType().getAsString();
return llvm::is_contained(Names, Name);
}
AST_MATCHER(FieldDecl, hasIntBitwidth) {
assert(Node.isBitField());
const ASTContext &Ctx = Node.getASTContext();
- unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
- unsigned CurrentBitWidth = Node.getBitWidthValue();
+ const unsigned IntBitWidth = Ctx.getIntWidth(Ctx.IntTy);
+ const unsigned CurrentBitWidth = Node.getBitWidthValue();
return IntBitWidth == CurrentBitWidth;
}
@@ -79,7 +79,7 @@ void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
const auto IsCeilFloorCallExpr = expr(callExpr(callee(functionDecl(
hasAnyName("::ceil", "::std::ceil", "::floor", "::std::floor")))));
- std::vector<StringRef> IgnoreConversionFromTypesVec =
+ const std::vector<StringRef> IgnoreConversionFromTypesVec =
utils::options::parseStringList(IgnoreConversionFromTypes);
// We may want to exclude other types from the checks, such as `size_type`
@@ -243,7 +243,7 @@ struct IntegerRange {
static IntegerRange createFromType(const ASTContext &Context,
const BuiltinType &T) {
if (T.isFloatingPoint()) {
- unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision(
+ const unsigned PrecisionBits = llvm::APFloatBase::semanticsPrecision(
Context.getFloatTypeSemantics(T.desugar()));
// Contrary to two's complement integer, floating point values are
// symmetric and have the same number of positive and negative values.
@@ -262,8 +262,8 @@ static IntegerRange createFromType(const ASTContext &Context,
return {LowerValue, UpperValue};
}
assert(T.isInteger() && "Unexpected builtin type");
- uint64_t TypeSize = Context.getTypeSize(&T);
- bool IsUnsignedInteger = T.isUnsignedInteger();
+ const uint64_t TypeSize = Context.getTypeSize(&T);
+ const bool IsUnsignedInteger = T.isUnsignedInteger();
return {llvm::APSInt::getMinValue(TypeSize, IsUnsignedInteger),
llvm::APSInt::getMaxValue(TypeSize, IsUnsignedInteger)};
}
@@ -271,15 +271,15 @@ static IntegerRange createFromType(const ASTContext &Context,
static bool isWideEnoughToHold(const ASTContext &Context,
const BuiltinType &FromType,
const BuiltinType &ToType) {
- IntegerRange FromIntegerRange = createFromType(Context, FromType);
- IntegerRange ToIntegerRange = createFromType(Context, ToType);
+ const IntegerRange FromIntegerRange = createFromType(Context, FromType);
+ const IntegerRange ToIntegerRange = createFromType(Context, ToType);
return ToIntegerRange.contains(FromIntegerRange);
}
static bool isWideEnoughToHold(const ASTContext &Context,
const llvm::APSInt &IntegerConstant,
const BuiltinType &ToType) {
- IntegerRange ToIntegerRange = createFromType(Context, ToType);
+ const IntegerRange ToIntegerRange = createFromType(Context, ToType);
return ToIntegerRange.contains(IntegerConstant);
}
@@ -289,13 +289,13 @@ static bool isWideEnoughToHold(const ASTContext &Context,
static bool isFloatExactlyRepresentable(const ASTContext &Context,
const llvm::APFloat &FloatConstant,
const QualType &DestType) {
- unsigned DestWidth = Context.getIntWidth(DestType);
- bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
+ const unsigned DestWidth = Context.getIntWidth(DestType);
+ const bool DestSigned = DestType->isSignedIntegerOrEnumerationType();
llvm::APSInt Result = llvm::APSInt(DestWidth, !DestSigned);
bool IsExact = false;
- bool Overflows = FloatConstant.convertToInteger(
- Result, llvm::APFloat::rmTowardZero, &IsExact) &
- llvm::APFloat::opInvalidOp;
+ const bool Overflows = FloatConstant.convertToInteger(
+ Result, llvm::APFloat::rmTowardZero, &IsExact) &
+ llvm::APFloat::opInvalidOp;
return !Overflows && IsExact;
}
@@ -321,8 +321,8 @@ bool NarrowingConversionsCheck::isWarningInhibitedByEquivalentSize(
// With this option, we don't warn on conversions that have equivalent width
// in bits. eg. uint32 <-> int32.
if (!WarnOnEquivalentBitWidth) {
- uint64_t FromTypeSize = Context.getTypeSize(&FromType);
- uint64_t ToTypeSize = Context.getTypeSize(&ToType);
+ const uint64_t FromTypeSize = Context.getTypeSize(&FromType);
+ const uint64_t ToTypeSize = Context.getTypeSize(&ToType);
if (FromTypeSize == ToTypeSize) {
return true;
}
@@ -406,8 +406,8 @@ void NarrowingConversionsCheck::handleIntegralCast(const ASTContext &Context,
// With this option, we don't warn on conversions that have equivalent width
// in bits. eg. uint32 <-> int32.
if (!WarnOnEquivalentBitWidth) {
- uint64_t FromTypeSize = Context.getTypeSize(FromType);
- uint64_t ToTypeSize = Context.getTypeSize(ToType);
+ const uint64_t FromTypeSize = Context.getTypeSize(FromType);
+ const uint64_t ToTypeSize = Context.getTypeSize(ToType);
if (FromTypeSize == ToTypeSize)
return;
}
@@ -583,7 +583,7 @@ void NarrowingConversionsCheck::handleImplicitCast(
return;
if (handleConditionalOperator(Context, Lhs, Rhs))
return;
- SourceLocation SourceLoc = Lhs.getExprLoc();
+ const SourceLocation SourceLoc = Lhs.getExprLoc();
switch (Cast.getCastKind()) {
case CK_BooleanToSignedIntegral:
handleBooleanToSignedIntegral(Context, SourceLoc, Lhs, Rhs);
diff --git a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
index abde115d10a1b..40305cab81c7f 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
@@ -60,7 +60,7 @@ void NondeterministicPointerIterationOrderCheck::check(
TemplateArgs[0].getAsType()->isPointerType();
if (IsAlgoArgPointer) {
- SourceRange R = RangeInit->getSourceRange();
+ const SourceRange R = RangeInit->getSourceRange();
diag(R.getBegin(), "iteration of pointers is nondeterministic") << R;
}
}
@@ -69,7 +69,7 @@ void NondeterministicPointerIterationOrderCheck::check(
const auto *SortPointers = Result.Nodes.getNodeAs<Stmt>("sortsemantic");
if ((SortPointers) && !(SortPointers->getBeginLoc().isMacroID())) {
- SourceRange R = SortPointers->getSourceRange();
+ const SourceRange R = SortPointers->getSourceRange();
diag(R.getBegin(), "sorting pointers is nondeterministic") << R;
}
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
index 08fae7b59bae5..7198c1b1c8aaf 100644
--- a/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/NotNullTerminatedResultCheck.cpp
@@ -120,18 +120,18 @@ static int getGivenLength(const MatchFinder::MatchResult &Result) {
if (Result.Nodes.getNodeAs<Expr>(UnknownLengthName))
return 0;
- if (int Length =
+ if (const int Length =
getLength(Result.Nodes.getNodeAs<Expr>(WrongLengthExprName), Result))
return Length;
- if (int Length =
+ if (const int Length =
getLength(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result))
return Length;
// Special case, for example 'strlen("foo")'.
if (const CallExpr *StrlenCE = getStrlenExpr(Result))
if (const Expr *Arg = StrlenCE->getArg(0)->IgnoreImpCasts())
- if (int ArgLength = getLength(Arg, Result))
+ if (const int ArgLength = getLength(Arg, Result))
return ArgLength;
return 0;
@@ -174,9 +174,9 @@ static bool isKnownDest(const MatchFinder::MatchResult &Result) {
// True if the capacity of the destination array is based on the given length,
// therefore we assume that it cannot overflow (e.g. 'malloc(given_length + 1)'
static bool isDestBasedOnGivenLength(const MatchFinder::MatchResult &Result) {
- StringRef DestCapacityExprStr =
+ const StringRef DestCapacityExprStr =
exprToStr(getDestCapacityExpr(Result), Result).trim();
- StringRef LengthExprStr =
+ const StringRef LengthExprStr =
exprToStr(Result.Nodes.getNodeAs<Expr>(LengthExprName), Result).trim();
return !DestCapacityExprStr.empty() && !LengthExprStr.empty() &&
@@ -226,8 +226,9 @@ isGivenLengthEqualToSrcLength(const MatchFinder::MatchResult &Result) {
if (isStringDataAndLength(Result))
return true;
- int GivenLength = getGivenLength(Result);
- int SrcLength = getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result);
+ const int GivenLength = getGivenLength(Result);
+ const int SrcLength =
+ getLength(Result.Nodes.getNodeAs<Expr>(SrcExprName), Result);
if (GivenLength != 0 && SrcLength != 0 && GivenLength == SrcLength)
return true;
@@ -261,15 +262,15 @@ static bool isDestCapacityOverflows(const MatchFinder::MatchResult &Result) {
return true;
const Expr *DestCapacityExpr = getDestCapacityExpr(Result);
- int DestCapacity = getLength(DestCapacityExpr, Result);
- int GivenLength = getGivenLength(Result);
+ const int DestCapacity = getLength(DestCapacityExpr, Result);
+ const int GivenLength = getGivenLength(Result);
if (GivenLength != 0 && DestCapacity != 0)
return isGivenLengthEqualToSrcLength(Result) && DestCapacity == GivenLength;
// Assume that the destination array's capacity cannot overflow if the
// expression of the memory allocation contains '+ 1'.
- StringRef DestCapacityExprStr = exprToStr(DestCapacityExpr, Result);
+ const StringRef DestCapacityExprStr = exprToStr(DestCapacityExpr, Result);
if (DestCapacityExprStr.contains("+1") || DestCapacityExprStr.contains("+ 1"))
return false;
@@ -297,7 +298,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
// See whether we work with a macro.
bool IsMacroDefinition = false;
- StringRef LengthExprStr = exprToStr(LengthExpr, Result);
+ const StringRef LengthExprStr = exprToStr(LengthExpr, Result);
Preprocessor::macro_iterator It = PP->macro_begin();
while (It != PP->macro_end() && !IsMacroDefinition) {
if (It->first->getName() == LengthExprStr)
@@ -309,7 +310,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
// Try to obtain an 'IntegerLiteral' and adjust it.
if (!IsMacroDefinition) {
if (const auto *LengthIL = dyn_cast<IntegerLiteral>(LengthExpr)) {
- uint64_t NewLength =
+ const uint64_t NewLength =
LengthIL->getValue().getZExtValue() +
(LengthHandle == LengthHandleKind::Increase ? 1 : -1);
@@ -347,7 +348,7 @@ static void lengthExprHandle(const Expr *LengthExpr,
}
// Try to inject the '+ 1'/'- 1' string.
- bool NeedInnerParen = BO && BO->getOpcode() != BO_Add;
+ const bool NeedInnerParen = BO && BO->getOpcode() != BO_Add;
if (NeedInnerParen)
Diag << FixItHint::CreateInsertion(LengthExpr->getBeginLoc(), "(");
@@ -384,8 +385,8 @@ static bool isDestExprFix(const MatchFinder::MatchResult &Result,
if (!Dest)
return false;
- std::string TempTyStr = Dest->getType().getAsString();
- StringRef TyStr = TempTyStr;
+ const std::string TempTyStr = Dest->getType().getAsString();
+ const StringRef TyStr = TempTyStr;
if (TyStr.starts_with("char") || TyStr.starts_with("wchar_t"))
return false;
@@ -397,7 +398,7 @@ static bool isDestExprFix(const MatchFinder::MatchResult &Result,
// increase the capacity by one to create space for the null terminator.
static bool isDestCapacityFix(const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
- bool IsOverflows = isDestCapacityOverflows(Result);
+ const bool IsOverflows = isDestCapacityOverflows(Result);
if (IsOverflows)
if (const Expr *CapacityExpr = getDestCapacityExpr(Result))
lengthExprHandle(CapacityExpr, LengthHandleKind::Increase, Result, Diag);
@@ -424,9 +425,9 @@ static void renameFunc(StringRef NewFuncName,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
- int FuncNameLength =
+ const int FuncNameLength =
FunctionExpr->getDirectCallee()->getIdentifier()->getLength();
- SourceRange FuncNameRange(
+ const SourceRange FuncNameRange(
FunctionExpr->getBeginLoc(),
FunctionExpr->getBeginLoc().getLocWithOffset(FuncNameLength - 1));
@@ -451,7 +452,7 @@ static void insertDestCapacityArg(bool IsOverflows, StringRef Name,
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
SmallString<64> NewSecondArg;
- if (int DestLength = getDestCapacity(Result)) {
+ if (const int DestLength = getDestCapacity(Result)) {
NewSecondArg = Twine(IsOverflows ? DestLength + 1 : DestLength).str();
} else {
NewSecondArg =
@@ -470,12 +471,12 @@ static void insertNullTerminatorExpr(StringRef Name,
const MatchFinder::MatchResult &Result,
DiagnosticBuilder &Diag) {
const auto *FunctionExpr = Result.Nodes.getNodeAs<CallExpr>(FunctionExprName);
- int FuncLocStartColumn = Result.SourceManager->getPresumedColumnNumber(
+ const int FuncLocStartColumn = Result.SourceManager->getPresumedColumnNumber(
FunctionExpr->getBeginLoc());
- SourceRange SpaceRange(
+ const SourceRange SpaceRange(
FunctionExpr->getBeginLoc().getLocWithOffset(-FuncLocStartColumn + 1),
FunctionExpr->getBeginLoc());
- StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
+ const StringRef SpaceBeforeStmtStr = Lexer::getSourceText(
CharSourceRange::getCharRange(SpaceRange), *Result.SourceManager,
Result.Context->getLangOpts(), nullptr);
@@ -717,10 +718,10 @@ void NotNullTerminatedResultCheck::registerMatchers(MatchFinder *Finder) {
};
auto MatchCall = [=](CallContext CC) {
- std::string CharHandlerFuncName = "::" + CC.Name.str();
+ const std::string CharHandlerFuncName = "::" + CC.Name.str();
// Try to match with 'wchar_t' based function calls.
- std::string WcharHandlerFuncName =
...
[truncated]
``````````
</details>
https://github.com/llvm/llvm-project/pull/167130
More information about the cfe-commits
mailing list