[clang-tools-extra] [clang-tidy] Improve integer comparison by matching valid expressions outside implicitCastExpr (PR #134188)

Baranov Victor via cfe-commits cfe-commits at lists.llvm.org
Tue May 27 21:50:53 PDT 2025


================
@@ -39,9 +39,11 @@ 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()))));
+
+  auto IntTypeExpr = expr(HasIntegerType);
----------------
vbvictor wrote:

```suggestion
  const auto IntTypeExpr = expr(HasIntegerType);
```
Just because everywhere else there is a `const`

https://github.com/llvm/llvm-project/pull/134188


More information about the cfe-commits mailing list