[clang-tools-extra] [clang-tidy] Fix false positive in misc-redundant-expression with type aliases (PR #198085)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Sat Jul 11 21:05:05 PDT 2026


================
@@ -44,6 +45,42 @@ static bool incrementWithoutOverflow(const APSInt &Value, APSInt &Result) {
   return Value < Result;
 }
 
+static bool areEquivalentDeclRefExpr(const DeclRefExpr *L,
+                                     const DeclRefExpr *R) {
+  if (L->getDecl() != R->getDecl())
+    return false;
+
+  const PrintingPolicy &Policy =
+      L->getDecl()->getASTContext().getPrintingPolicy();
+
+  if (L->hasQualifier() != R->hasQualifier())
+    return false;
+  if (L->hasQualifier()) {
+    std::string LQual, RQual;
+    llvm::raw_string_ostream LOS(LQual), ROS(RQual);
+    L->getQualifier().print(LOS, Policy);
+    R->getQualifier().print(ROS, Policy);
+    if (LQual != RQual)
+      return false;
+  }
+
+  if (L->hasExplicitTemplateArgs() != R->hasExplicitTemplateArgs())
+    return false;
+  if (L->hasExplicitTemplateArgs()) {
+    if (L->getNumTemplateArgs() != R->getNumTemplateArgs())
+      return false;
+    for (unsigned I = 0, E = L->getNumTemplateArgs(); I != E; ++I) {
+      std::string LArg, RArg;
+      llvm::raw_string_ostream LOS(LArg), ROS(RArg);
+      L->getTemplateArgs()[I].getArgument().print(Policy, LOS, true);
+      R->getTemplateArgs()[I].getArgument().print(Policy, ROS, true);
+      if (LArg != RArg)
+        return false;
+    }
----------------
zwuis wrote:

Use `llvm::equal`.

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


More information about the cfe-commits mailing list