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

Matheus Izvekov via cfe-commits cfe-commits at lists.llvm.org
Thu Apr 30 16:52:29 PDT 2026


================
@@ -12860,6 +12837,33 @@ QualType Sema::CheckCompareOperands(ExprResult &LHS, ExprResult &RHS,
     return Ty->isPointerType() || Ty->isMemberPointerType();
   };
 
+  // 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 (getLangOpts().CPlusPlus && LHSStripped->getType()->isArrayType() &&
+      RHSStripped->getType()->isArrayType()) {
+
+    // In an SFINAE context, don't emit an error.
+    // Just return the operands so the caller can return false.
+    if (isSFINAEContext()) {
+      return InvalidOperands(Loc, LHS, RHS);
+    }
----------------
mizvekov wrote:

Yes we can rely on error suppression in SFINAE context, but it's better in that case to then return some sort of error instead of continuing or trying to error recover, because the language spec mandates we stop upon first error in a substitution failure, and doing otherwise can allow side-effects which are not allowed, like template instantiations, and cause us to reject a valid program.

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


More information about the cfe-commits mailing list