[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr for use-integer-sign-comparison (PR #144240)
Baranov Victor via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 12 14:22:21 PDT 2025
================
@@ -39,21 +39,23 @@ intCastExpression(bool IsSigned,
// std::cmp_{} functions trigger a compile-time error if either LHS or RHS
// is a non-integer type, char, enum or bool
// (unsigned char/ signed char are Ok and can be used).
- auto IntTypeExpr = expr(hasType(hasCanonicalType(qualType(
+ const auto HasIntegerType = hasType(hasCanonicalType(qualType(
isInteger(), IsSigned ? isSignedInteger() : isUnsignedInteger(),
- unless(isActualChar()), unless(booleanType()), unless(enumType())))));
+ unless(isActualChar()), unless(booleanType()), unless(enumType()))));
+
+ const auto IntTypeExpr = expr(HasIntegerType);
const auto ImplicitCastExpr =
- CastBindName.empty() ? implicitCastExpr(hasSourceExpression(IntTypeExpr))
- : implicitCastExpr(hasSourceExpression(IntTypeExpr))
- .bind(CastBindName);
+ implicitCastExpr(hasSourceExpression(IntTypeExpr)).bind(CastBindName);
+
+ const auto ExplicitCastExpr =
+ anyOf(explicitCastExpr(has(ImplicitCastExpr)),
----------------
vbvictor wrote:
This line is excessive, `ignoringImpCasts(explicitCastExpr(has(ImplicitCastExpr)))` must work when there are no `ImpCasts`, then it just becomes `explicitCastExpr(has(ImplicitCastExpr))`.
https://github.com/llvm/llvm-project/pull/144240
More information about the cfe-commits
mailing list