diff --git a/flang/lib/evaluate/fold.cc b/flang/lib/evaluate/fold.cc index 17d774178fb3..c6f814449c8c 100644 --- a/flang/lib/evaluate/fold.cc +++ b/flang/lib/evaluate/fold.cc @@ -158,8 +158,13 @@ DataRef FoldOperation(FoldingContext &context, DataRef &&dataRef) { } Substring FoldOperation(FoldingContext &context, Substring &&substring) { - std::optional> lower{Fold(context, substring.lower())}; - std::optional> upper{Fold(context, substring.upper())}; + std::optional> lower, upper; + if (auto *p{substring.lower()}) { + lower = Fold(context, std::move(*p)); + } + if (auto *p{substring.upper()}) { + upper = Fold(context, std::move(*p)); + } if (const DataRef * dataRef{substring.GetParentIf()}) { return Substring{FoldOperation(context, DataRef{*dataRef}), std::move(lower), std::move(upper)};