diff --git a/flang/lib/Evaluate/fold-implementation.h b/flang/lib/Evaluate/fold-implementation.h --- a/flang/lib/Evaluate/fold-implementation.h +++ b/flang/lib/Evaluate/fold-implementation.h @@ -1154,14 +1154,20 @@ if (auto array{ApplyElementwise(context, convert)}) { return *array; } + struct { + FoldingContext &context; + Convert &convert; + } msvcWorkaround{context, convert}; return std::visit( - [&context, &convert](auto &kindExpr) -> Expr { + [&msvcWorkaround](auto &kindExpr) -> Expr { using Operand = ResultType; // This variable is a workaround for msvc which emits an error when // using the FROMCAT template parameter below. TypeCategory constexpr FromCat{FROMCAT}; + auto &convert{msvcWorkaround.convert}; char buffer[64]; if (auto value{GetScalarConstantValue(kindExpr)}) { + FoldingContext &context{msvcWorkaround.context}; if constexpr (TO::category == TypeCategory::Integer) { if constexpr (Operand::category == TypeCategory::Integer) { auto converted{Scalar::ConvertSigned(*value)};