[clang] [clang] Reject array comparisons in C++26 for unknown/dependent types in templates (PR #191101)

via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 18 09:21:23 PDT 2026


================
@@ -12860,6 +12837,39 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
     return Ty->isPointerType() || Ty->isMemberPointerType();
   };
 
+  // If types are arrays, skip this check so we can throw an error later.
+  if (this->inTemplateInstantiation()) {
+    QualType LHSType = LHS.get()->getType();
+    QualType RHSType = RHS.get()->getType();
+    if (!LHSType->isArrayType() && !RHSType->isArrayType())
+      return QualType();
+  }
+
+  // C++1a [array.comp]:
+  //   Equality and relational comparisons ([expr.eq], [expr.rel]) between two
+  //   operands of array type.
+  // C++2a [depr.array.comp]:
+  //   Equality and relational comparisons ([expr.eq], [expr.rel]) between two
+  //   operands of array type are deprecated.
+  Expr *LHSStripped = LHS.get()->IgnoreParenImpCasts();
+  Expr *RHSStripped = RHS.get()->IgnoreParenImpCasts();
+  if (this->getLangOpts().CPlusPlus && LHSStripped->getType()->isArrayType() &&
----------------
PrabbyDD wrote:

Ok just pushed the code changes and updated the test. Let me know what you think. 

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


More information about the cfe-commits mailing list