[clang-tools-extra] [clang-tidy] Improve redundant-casting check for binary operation (PR #191386)

Zeyi Xu via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 16 02:21:36 PDT 2026


================
@@ -64,13 +64,20 @@ static bool areBinaryOperatorOperandsTypesEqualToOperatorResultType(
 
     const QualType NonReferenceType = Type.getNonReferenceType();
     const QualType LHSType = B->getLHS()->IgnoreImplicit()->getType();
-    if (LHSType.isNull() || !areTypesEqual(LHSType.getNonReferenceType(),
-                                           NonReferenceType, IgnoreTypeAliases))
-      return false;
     const QualType RHSType = B->getRHS()->IgnoreImplicit()->getType();
-    if (RHSType.isNull() || !areTypesEqual(RHSType.getNonReferenceType(),
-                                           NonReferenceType, IgnoreTypeAliases))
+    const bool LHSMatches =
+        !LHSType.isNull() && areTypesEqual(LHSType.getNonReferenceType(),
+                                           NonReferenceType, IgnoreTypeAliases);
+    const bool RHSMatches =
+        !RHSType.isNull() && areTypesEqual(RHSType.getNonReferenceType(),
+                                           NonReferenceType, IgnoreTypeAliases);
+    if (!IgnoreImplicitCasts) {
----------------
zeyi2 wrote:

```cpp
if (!LHSMatches || (IgnoreImplicitCasts && !RHSMatches)) {
  return false;
}
```

WDYT?

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


More information about the cfe-commits mailing list