Error optional arrays

Error optional arrays

Dear all,

I stumbled upon a compiler-error (or is it a restriction in the standard?) with passing optional arrays in mixed assumed- and explicit shape.

module m
    implicit none
    ! explicit shape optional
    subroutine take_optional(arg)
        integer, dimension(1), optional :: arg
        print *, present(arg)   ! output is "F"
    end subroutine
    ! assumed shape optional
    subroutine pass_optional(arg)
        integer, dimension(:), optional :: arg
        call take_optional(arg)  ! expects explicit shape
    end subroutine
end module
program p
    use m
    implicit none
    integer, dimension(1) :: arg
    arg = [1]
    call pass_optional(arg)
end program

The assumed-shape array is passed to a second subroutine which expects explicit shape. It is however not present any more, and any attempt to access it will cause a runtime error. Compiler is ifort 14.0.1, all default options.

Your comments are appreciated.

With regards

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Just checked it, got "T" for ifort 12.1.2 and 13.0.1, gfortran 4.6.3 and "F" for ifort  14.0.1, all with default options

Leave a Comment

Please sign in to add a comment. Not a member? Join today