} else if (name == "repeat") { // not elemental
if (auto scalars{GetScalarConstantArguments<T, SubscriptInteger>(
context, funcRef.arguments())}) {
- return Expr<T>{Constant<T>{
- CharacterUtils<KIND>::REPEAT(std::get<Scalar<T>>(*scalars),
- std::get<Scalar<SubscriptInteger>>(*scalars).ToInt64())}};
+ auto str{std::get<Scalar<T>>(*scalars)};
+ auto n{std::get<Scalar<SubscriptInteger>>(*scalars).ToInt64()};
+ if (static_cast<double>(n) * str.size() >
+ (1 << 20)) { // sanity limit of 1MiB
+ context.messages().Say(
+ "Result of REPEAT() is too large to compute at compilation time (%g characters)"_port_en_US,
+ static_cast<double>(n) * str.size());
+ } else {
+ return Expr<T>{Constant<T>{CharacterUtils<KIND>::REPEAT(str, n)}};
+ }
}
} else if (name == "trim") { // not elemental
if (auto scalar{
!CHERK: error: Must be a constant value
integer, parameter :: bad2 = storage_size(y)
end subroutine
+ subroutine s13
+ !CHECK: portability: Result of REPEAT() is too large to compute at compilation time (1.1259e+15 characters)
+ print *, repeat(repeat(' ', 2**20), 2**30)
+ end subroutine
subroutine warnings
real, parameter :: ok1 = scale(0.0, 99999) ! 0.0
real, parameter :: ok2 = scale(1.0, -99999) ! 0.0