@@ -1735,7 +1735,8 @@ Expr<TO> FoldOperation(
17351735 if (auto value{GetScalarConstantValue<Operand>(kindExpr)}) {
17361736 FoldingContext &ctx{msvcWorkaround.context };
17371737 if constexpr (TO::category == TypeCategory::Integer) {
1738- if constexpr (FromCat == TypeCategory::Integer) {
1738+ if constexpr (FromCat == TypeCategory::Integer ||
1739+ FromCat == TypeCategory::Unsigned) {
17391740 auto converted{Scalar<TO>::ConvertSigned (*value)};
17401741 if (converted.overflow &&
17411742 msvcWorkaround.context .languageFeatures ().ShouldWarn (
@@ -1762,9 +1763,20 @@ Expr<TO> FoldOperation(
17621763 }
17631764 return ScalarConstantToExpr (std::move (converted.value ));
17641765 }
1766+ } else if constexpr (TO::category == TypeCategory::Unsigned) {
1767+ if constexpr (FromCat == TypeCategory::Integer ||
1768+ FromCat == TypeCategory::Unsigned) {
1769+ return Expr<TO>{
1770+ Constant<TO>{Scalar<TO>::ConvertUnsigned (*value).value }};
1771+ } else if constexpr (FromCat == TypeCategory::Real) {
1772+ return Expr<TO>{
1773+ Constant<TO>{value->template ToInteger <Scalar<TO>>().value }};
1774+ }
17651775 } else if constexpr (TO::category == TypeCategory::Real) {
1766- if constexpr (FromCat == TypeCategory::Integer) {
1767- auto converted{Scalar<TO>::FromInteger (*value)};
1776+ if constexpr (FromCat == TypeCategory::Integer ||
1777+ FromCat == TypeCategory::Unsigned) {
1778+ auto converted{Scalar<TO>::FromInteger (
1779+ *value, FromCat == TypeCategory::Unsigned)};
17681780 if (!converted.flags .empty ()) {
17691781 char buffer[64 ];
17701782 std::snprintf (buffer, sizeof buffer,
0 commit comments