[clang] [libcxx] [llvm] [Clang] Add warnings when mixing different charN_t types (PR #138708)
via llvm-commits
llvm-commits at lists.llvm.org
Sat May 10 14:00:33 PDT 2025
================
@@ -11810,6 +11811,46 @@ static void DiagnoseIntInBoolContext(Sema &S, Expr *E) {
}
}
+static void DiagnoseMixedUnicodeImplicitConversion(Sema &S, const Type *Source,
+ const Type *Target, Expr *E,
+ QualType T,
+ SourceLocation CC) {
+ assert(Source->isUnicodeCharacterType() && Target->isUnicodeCharacterType() &&
+ Source != Target);
+ Expr::EvalResult Result;
+ if (E->EvaluateAsInt(Result, S.getASTContext(), Expr::SE_AllowSideEffects,
+ S.isConstantEvaluatedContext())) {
+ llvm::APSInt Value(32);
+ Value = Result.Val.getInt();
+ bool IsASCII = Value <= 0x7F;
+ bool IsBMP = Value <= 0xD7FF || (Value >= 0xE000 && Value <= 0xFFFF);
+ bool ConversionPreservesSemantics =
+ IsASCII || (!Source->isChar8Type() && !Target->isChar8Type() && IsBMP);
----------------
cor3ntin wrote:
Consider `char8_t(0x80)` - This is not ASCII, is BMP and cannot be safely converted to another charN_t
https://github.com/llvm/llvm-project/pull/138708
More information about the llvm-commits
mailing list