[clang] [Clang] Fix conversion from floats to bool-backed enums per CWG1094 (PR #211172)
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 22 01:18:25 PDT 2026
================
@@ -1489,16 +1489,26 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr,
SrcExpr = ExprError();
return TC_Failed;
}
+ // [expr.static.cast]p8
+ // If the enumeration type has a fixed underlying type, the value is
+ // first converted to that type by integral promotion ([conv.prom]) or
+ // integral conversion ([conv.integral]), if necessary, and then to the
+ // enumeration type.
+ const auto *ED = DestType->castAsEnumDecl();
+ bool DestIsFixedBoolean =
+ ED->isFixed() && ED->getIntegerType()->isBooleanType();
if (SrcType->isIntegralOrEnumerationType()) {
- // [expr.static.cast]p10 If the enumeration type has a fixed underlying
- // type, the value is first converted to that type by integral conversion
- const auto *ED = DestType->castAsEnumDecl();
- Kind = ED->isFixed() && ED->getIntegerType()->isBooleanType()
- ? CK_IntegralToBoolean
- : CK_IntegralCast;
+ Kind = DestIsFixedBoolean ? CK_IntegralToBoolean : CK_IntegralCast;
return TC_Success;
} else if (SrcType->isRealFloatingType()) {
- Kind = CK_FloatingToIntegral;
+ // [expr.static.cast]p8
----------------
cor3ntin wrote:
```suggestion
//C++26 [expr.static.cast]p8
```
https://github.com/llvm/llvm-project/pull/211172
More information about the cfe-commits
mailing list