[clang-tools-extra] [clang-tidy][NFC] Fix miscellaneous clang-tidy warnings over codebase (PR #164096)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sat Oct 18 14:57:59 PDT 2025
https://github.com/vbvictor updated https://github.com/llvm/llvm-project/pull/164096
>From 3c6d982fa6860d9a9c3976492593da567b8ced4a Mon Sep 17 00:00:00 2001
From: Victor Baranov <bar.victor.2002 at gmail.com>
Date: Sat, 18 Oct 2025 18:25:43 +0300
Subject: [PATCH 1/2] [clang-tidy][NFC] Fix miscellaneous clang-tidy warnings
over codebase
---
clang-tools-extra/clang-tidy/ClangTidyOptions.cpp | 2 ++
.../clang-tidy/altera/UnrollLoopsCheck.cpp | 8 ++++----
.../bugprone/EasilySwappableParametersCheck.cpp | 2 +-
.../clang-tidy/bugprone/SizeofExpressionCheck.cpp | 12 ++++++------
.../clang-tidy/bugprone/VirtualNearMissCheck.cpp | 7 ++++---
.../clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp | 10 +++++-----
.../clang-tidy/misc/NewDeleteOverloadsCheck.cpp | 2 +-
.../clang-tidy/modernize/LoopConvertCheck.cpp | 7 ++++---
.../clang-tidy/modernize/LoopConvertUtils.cpp | 2 +-
.../clang-tidy/modernize/UseAutoCheck.cpp | 4 ++--
.../readability/ImplicitBoolConversionCheck.cpp | 4 ++--
.../clang-tidy/readability/QualifiedAutoCheck.cpp | 9 ++++-----
.../readability/SuspiciousCallArgumentCheck.cpp | 4 ++--
13 files changed, 38 insertions(+), 35 deletions(-)
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index b752a9beb0e34..21455db7c7e7b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -154,6 +154,7 @@ template <> struct ScalarEnumerationTraits<clang::DiagnosticIDs::Level> {
}
};
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckDiag> {
+ // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
static const bool flow = false;
};
template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
@@ -165,6 +166,7 @@ template <> struct MappingTraits<ClangTidyOptions::CustomCheckDiag> {
}
};
template <> struct SequenceElementTraits<ClangTidyOptions::CustomCheckValue> {
+ // NOLINTNEXTLINE(readability-identifier-naming) Defined by YAMLTraits.h
static const bool flow = false;
};
template <> struct MappingTraits<ClangTidyOptions::CustomCheckValue> {
diff --git a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
index 6aad3c6b191ed..e90cdd00eb1fe 100644
--- a/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/altera/UnrollLoopsCheck.cpp
@@ -215,13 +215,13 @@ bool UnrollLoopsCheck::hasLargeNumIterations(const Stmt *Statement,
break;
case (BO_MulAssign):
Iterations =
- 1 + (std::log((double)EndValue) - std::log((double)InitValue)) /
- std::log((double)ConstantValue);
+ 1 + ((std::log((double)EndValue) - std::log((double)InitValue)) /
+ std::log((double)ConstantValue));
break;
case (BO_DivAssign):
Iterations =
- 1 + (std::log((double)InitValue) - std::log((double)EndValue)) /
- std::log((double)ConstantValue);
+ 1 + ((std::log((double)InitValue) - std::log((double)EndValue)) /
+ std::log((double)ConstantValue));
break;
default:
// All other operators are not handled; assume large bounds.
diff --git a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
index d8207b30f1b5e..b4ee35154f5f0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/EasilySwappableParametersCheck.cpp
@@ -1074,7 +1074,7 @@ approximateStandardConversionSequence(const TheCheck &Check, QualType From,
WorkType = To;
}
- if (Ctx.hasSameType(WorkType, To)) {
+ if (ASTContext::hasSameType(WorkType, To)) {
LLVM_DEBUG(llvm::dbgs() << "<<< approximateStdConv. Reached 'To' type.\n");
return {Ctx.getCommonSugaredType(WorkType, To)};
}
diff --git a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
index cdb6a088b9d0a..cf55dd718f532 100644
--- a/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/SizeofExpressionCheck.cpp
@@ -424,7 +424,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
"suspicious usage of 'sizeof(array)/sizeof(...)';"
" denominator differs from the size of array elements")
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
- } else if (NumTy && DenomTy && Ctx.hasSameType(NumTy, DenomTy) &&
+ } else if (NumTy && DenomTy && ASTContext::hasSameType(NumTy, DenomTy) &&
!NumTy->isDependentType()) {
// Dependent type should not be compared.
diag(E->getOperatorLoc(),
@@ -433,7 +433,7 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
<< E->getLHS()->getSourceRange() << E->getRHS()->getSourceRange();
} else if (!WarnOnSizeOfPointer) {
// When 'WarnOnSizeOfPointer' is enabled, these messages become redundant:
- if (PointedTy && DenomTy && Ctx.hasSameType(PointedTy, DenomTy)) {
+ if (PointedTy && DenomTy && ASTContext::hasSameType(PointedTy, DenomTy)) {
diag(E->getOperatorLoc(),
"suspicious usage of 'sizeof(...)/sizeof(...)'; size of pointer "
"is divided by size of pointed type")
@@ -462,8 +462,8 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *SizeOfExpr =
Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>("sizeof-ptr-mul-expr");
- if (Ctx.hasSameType(LPtrTy, RPtrTy) &&
- Ctx.hasSameType(LPtrTy, SizeofArgTy)) {
+ if (ASTContext::hasSameType(LPtrTy, RPtrTy) &&
+ ASTContext::hasSameType(LPtrTy, SizeofArgTy)) {
diag(SizeOfExpr->getBeginLoc(), "suspicious usage of 'sizeof(...)' in "
"pointer arithmetic")
<< SizeOfExpr->getSourceRange() << E->getOperatorLoc()
@@ -477,8 +477,8 @@ void SizeofExpressionCheck::check(const MatchFinder::MatchResult &Result) {
const auto *SizeOfExpr =
Result.Nodes.getNodeAs<UnaryExprOrTypeTraitExpr>("sizeof-ptr-div-expr");
- if (Ctx.hasSameType(LPtrTy, RPtrTy) &&
- Ctx.hasSameType(LPtrTy, SizeofArgTy)) {
+ if (ASTContext::hasSameType(LPtrTy, RPtrTy) &&
+ ASTContext::hasSameType(LPtrTy, SizeofArgTy)) {
diag(SizeOfExpr->getBeginLoc(), "suspicious usage of 'sizeof(...)' in "
"pointer arithmetic")
<< SizeOfExpr->getSourceRange() << E->getOperatorLoc()
diff --git a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
index 0c8d2b8ef40f9..cef8b4da7fc17 100644
--- a/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/VirtualNearMissCheck.cpp
@@ -50,7 +50,7 @@ static bool checkOverridingFunctionReturnType(const ASTContext *Context,
return false;
// Check if return types are identical.
- if (Context->hasSameType(DerivedReturnTy, BaseReturnTy))
+ if (ASTContext::hasSameType(DerivedReturnTy, BaseReturnTy))
return true;
/// Check if the return types are covariant.
@@ -77,7 +77,7 @@ static bool checkOverridingFunctionReturnType(const ASTContext *Context,
if (DRD == BRD)
return true;
- if (!Context->hasSameUnqualifiedType(DTy, BTy)) {
+ if (!ASTContext::hasSameUnqualifiedType(DTy, BTy)) {
// Begin checking whether the conversion from D to B is valid.
CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
/*DetectVirtual=*/false);
@@ -87,7 +87,8 @@ static bool checkOverridingFunctionReturnType(const ASTContext *Context,
return false;
// Check ambiguity.
- if (Paths.isAmbiguous(Context->getCanonicalType(BTy).getUnqualifiedType()))
+ if (Paths.isAmbiguous(
+ ASTContext::getCanonicalType(BTy).getUnqualifiedType()))
return false;
// Check accessibility.
diff --git a/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp b/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp
index 0d81b9a9e38ca..bd51cc5037dca 100644
--- a/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp
+++ b/clang-tools-extra/clang-tidy/llvm/UseNewMLIROpBuilderCheck.cpp
@@ -111,10 +111,10 @@ EditGenerator rewrite(RangeSelector Call, RangeSelector Builder,
}
RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
- Stencil message = cat("use 'OpType::create(builder, ...)' instead of "
+ Stencil Message = cat("use 'OpType::create(builder, ...)' instead of "
"'builder.create<OpType>(...)'");
// Match a create call on an OpBuilder.
- ast_matchers::internal::Matcher<Stmt> base =
+ ast_matchers::internal::Matcher<Stmt> Base =
cxxMemberCallExpr(
on(expr(hasType(
cxxRecordDecl(isSameOrDerivedFrom("::mlir::OpBuilder"))))
@@ -124,10 +124,10 @@ RewriteRuleWith<std::string> useNewMlirOpBuilderCheckRule() {
.bind("call");
return applyFirst(
// Attempt rewrite given an lvalue builder, else just warn.
- {makeRule(cxxMemberCallExpr(unless(on(cxxTemporaryObjectExpr())), base),
+ {makeRule(cxxMemberCallExpr(unless(on(cxxTemporaryObjectExpr())), Base),
rewrite(node("call"), node("builder"), callArgs("call")),
- message),
- makeRule(base, noopEdit(node("call")), message)});
+ Message),
+ makeRule(Base, noopEdit(node("call")), Message)});
}
} // namespace
diff --git a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
index 5e0f32a900ea8..9801c9ea04d2d 100644
--- a/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/NewDeleteOverloadsCheck.cpp
@@ -53,7 +53,7 @@ AST_MATCHER(FunctionDecl, isPlacementOverload) {
const auto *FPT = Node.getType()->castAs<FunctionProtoType>();
ASTContext &Ctx = Node.getASTContext();
if (Ctx.getLangOpts().SizedDeallocation &&
- Ctx.hasSameType(FPT->getParamType(1), Ctx.getSizeType()))
+ ASTContext::hasSameType(FPT->getParamType(1), Ctx.getSizeType()))
return false;
return true;
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
index 37482583760f2..fea5ac6f29eff 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
@@ -499,7 +499,7 @@ static bool canBeModified(ASTContext *Context, const Expr *E) {
return true;
if (const auto *Cast = Parents[0].get<ImplicitCastExpr>()) {
if ((Cast->getCastKind() == CK_NoOp &&
- Context->hasSameType(Cast->getType(), E->getType().withConst())) ||
+ ASTContext::hasSameType(Cast->getType(), E->getType().withConst())) ||
(Cast->getCastKind() == CK_LValueToRValue &&
!Cast->getType().isNull() && Cast->getType()->isFundamentalType()))
return false;
@@ -664,7 +664,8 @@ void LoopConvertCheck::doConversion(
AliasVarIsRef = true;
}
if (Descriptor.ElemType.isNull() ||
- !Context->hasSameUnqualifiedType(AliasVarType, Descriptor.ElemType))
+ !ASTContext::hasSameUnqualifiedType(AliasVarType,
+ Descriptor.ElemType))
Descriptor.ElemType = AliasVarType;
}
@@ -944,7 +945,7 @@ bool LoopConvertCheck::isConvertible(ASTContext *Context,
CanonicalInitVarType->isPointerType()) {
// If the initializer and the variable are both pointers check if the
// un-qualified pointee types match, otherwise we don't use auto.
- return Context->hasSameUnqualifiedType(
+ return ASTContext::hasSameUnqualifiedType(
CanonicalBeginType->getPointeeType(),
CanonicalInitVarType->getPointeeType());
}
diff --git a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
index 286c39be44ce4..586deea46e86f 100644
--- a/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/LoopConvertUtils.cpp
@@ -370,7 +370,7 @@ static bool isAliasDecl(ASTContext *Context, const Decl *TheDecl,
DeclarationType = DeclarationType.getNonReferenceType();
if (InitType.isNull() || DeclarationType.isNull() ||
- !Context->hasSameUnqualifiedType(DeclarationType, InitType))
+ !ASTContext::hasSameUnqualifiedType(DeclarationType, InitType))
return false;
}
diff --git a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
index c7fd0a9695952..01796a6f4af2d 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
@@ -316,7 +316,7 @@ void UseAutoCheck::replaceIterators(const DeclStmt *D, ASTContext *Context) {
if (NestedConstruct->getConstructor()->isConvertingConstructor(false))
return;
}
- if (!Context->hasSameType(V->getType(), E->getType()))
+ if (!ASTContext::hasSameType(V->getType(), E->getType()))
return;
}
@@ -378,7 +378,7 @@ void UseAutoCheck::replaceExpr(
return;
// If VarDecl and Initializer have mismatching unqualified types.
- if (!Context->hasSameUnqualifiedType(V->getType(), GetType(Expr)))
+ if (!ASTContext::hasSameUnqualifiedType(V->getType(), GetType(Expr)))
return;
// All subsequent variables in this declaration should have the same
diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index bfdf9cbd92d2b..6f6da57d7822b 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -51,7 +51,7 @@ static StringRef getZeroLiteralToCompareWithForType(CastKind CastExprKind,
return Type->isUnsignedIntegerType() ? "0u" : "0";
case CK_FloatingToBoolean:
- return Context.hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0";
+ return ASTContext::hasSameType(Type, Context.FloatTy) ? "0.0f" : "0.0";
case CK_PointerToBoolean:
case CK_MemberPointerToBoolean: // Fall-through on purpose.
@@ -215,7 +215,7 @@ getEquivalentForBoolLiteral(const CXXBoolLiteralExpr *BoolLiteral,
}
if (DestType->isFloatingType()) {
- if (Context.hasSameType(DestType, Context.FloatTy)) {
+ if (ASTContext::hasSameType(DestType, Context.FloatTy)) {
return BoolLiteral->getValue() ? "1.0f" : "0.0f";
}
return BoolLiteral->getValue() ? "1.0" : "0.0";
diff --git a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
index dc9510d1dab62..942a0a8a4469f 100644
--- a/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/QualifiedAutoCheck.cpp
@@ -142,12 +142,11 @@ void QualifiedAutoCheck::registerMatchers(MatchFinder *Finder) {
if (this->IgnoreAliasing) {
return qualType(
hasUnqualifiedDesugaredType(pointerType(pointee(InnerMatchers...))));
- } else {
- return qualType(
- anyOf(qualType(pointerType(pointee(InnerMatchers...))),
- qualType(substTemplateTypeParmType(hasReplacementType(
- pointerType(pointee(InnerMatchers...)))))));
}
+ return qualType(anyOf(qualType(pointerType(pointee(InnerMatchers...))),
+ qualType(substTemplateTypeParmType(hasReplacementType(
+ pointerType(pointee(InnerMatchers...)))))));
+
};
auto IsAutoDeducedToPointer =
diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index d1738f10e0f93..6145ff110c127 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -288,8 +288,8 @@ static bool applyDiceHeuristic(StringRef Arg, StringRef Param,
std::size_t Intersection = 0;
// Find the intersection between the two sets.
- for (auto IT = ParamBigrams.begin(); IT != ParamBigrams.end(); ++IT)
- Intersection += ArgBigrams.count((IT->getKey()));
+ for (const auto &[Key, Value] : ParamBigrams)
+ Intersection += ArgBigrams.count(Key);
// Calculate Dice coefficient.
return percentage(Intersection * 2.0,
>From 6815c46629bd306f9b4cbf9cf76cc9bc4c11ffd3 Mon Sep 17 00:00:00 2001
From: Baranov Victor <bar.victor.2002 at gmail.com>
Date: Sun, 19 Oct 2025 00:57:51 +0300
Subject: [PATCH 2/2] Update
clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
Co-authored-by: Victor Chernyakin <chernyakin.victor.j at outlook.com>
---
.../clang-tidy/readability/SuspiciousCallArgumentCheck.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
index 6145ff110c127..feb248dd62411 100644
--- a/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SuspiciousCallArgumentCheck.cpp
@@ -288,7 +288,7 @@ static bool applyDiceHeuristic(StringRef Arg, StringRef Param,
std::size_t Intersection = 0;
// Find the intersection between the two sets.
- for (const auto &[Key, Value] : ParamBigrams)
+ for (const auto &[Key, _] : ParamBigrams)
Intersection += ArgBigrams.count(Key);
// Calculate Dice coefficient.
More information about the cfe-commits
mailing list