Passing element of an optional array as optional scalar argument

I just encountered the same problem, and I’m wondering if F2023 (see reference below) can solve this situation using the new form of conditional expression?

        subroutine optnl_array(array)
            integer, intent(in), optional :: array(10)
            call optnl_scalar(present(array) ? array(5) : .nil.) ! Is this legal?
        end subroutine optnl_array
        subroutine optnl_scalar(s)
            integer, intent(in), optional :: s
            if (present(s)) then
                print *, 'S is present, ',s
            else
                print *, 'S not present'
            endif
        end subroutine

References:

This is pretty much one of the canonical use cases for the conditional expr/arg syntax.

4 Likes