================ @@ -1567,15 +1568,81 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, } } +static void CheckUnicodeArithmeticConversions(Sema &SemaRef, Expr *LHS, + Expr *RHS, SourceLocation Loc, + ArithConvKind ACK) { + QualType LHSType = LHS->getType().getUnqualifiedType(); + QualType RHSType = RHS->getType().getUnqualifiedType(); + + if (!SemaRef.getLangOpts().CPlusPlus || !LHSType->isUnicodeCharacterType() || + !RHSType->isUnicodeCharacterType()) + return; + + if (ACK == ArithConvKind::Comparison) { + if (SemaRef.getASTContext().hasSameType(LHSType, RHSType)) + return; + + Expr::EvalResult LHSRes, RHSRes; + bool Success = LHS->EvaluateAsInt(LHSRes, SemaRef.getASTContext(), + Expr::SE_AllowSideEffects, + SemaRef.isConstantEvaluatedContext()); + if (Success) + Success = RHS->EvaluateAsInt(RHSRes, SemaRef.getASTContext(), + Expr::SE_AllowSideEffects, + SemaRef.isConstantEvaluatedContext()); + if (Success) { + llvm::APSInt LHSValue(32); + LHSValue = LHSRes.Val.getInt(); + llvm::APSInt RHSValue(32); + RHSValue = RHSRes.Val.getInt(); + + auto IsSingleCodeUnitCP = [](const QualType &T, + const llvm::APSInt &Value) { + if (T->isChar8Type()) + return llvm::IsSingleCodeUnitUTF8Codepoint(Value.getExtValue()); + if (T->isChar16Type()) + return llvm::IsSingleCodeUnitUTF16Codepoint(Value.getExtValue()); + return llvm::IsSingleCodeUnitUTF32Codepoint(Value.getExtValue()); + }; ---------------- cor3ntin wrote:
Do you feel strongly about it? It appears in 2 places; it was either duplicating it or adding it as a member of Sema, which did not seem to be worth it https://github.com/llvm/llvm-project/pull/138708 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits