[clang] [Clang] Add diagnostic when scoped enumeration requires an explicit conversion for binary operations (PR #152698)

Yanzuo Liu via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 8 20:54:42 PDT 2025


================
@@ -10772,9 +10811,14 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
   if (LHS.isInvalid() || RHS.isInvalid())
     return QualType();
 
-
-  if (compType.isNull() || !compType->isArithmeticType())
-    return InvalidOperands(Loc, LHS, RHS);
+  if (compType.isNull() || !compType->isArithmeticType()) {
+    InvalidOperands(Loc, LHS, RHS);
+    diagnoseScopedEnums(*this, Loc, LHS, RHS,
+                        IsCompAssign ? IsDiv ? BO_DivAssign : BO_MulAssign
+                        : IsDiv      ? BO_Div
+                                     : BO_Mul);
----------------
zwuis wrote:

Nested `? :` seems not good for readability. What about converting outer `? :` to `if` statement?

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


More information about the cfe-commits mailing list