Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

Error optional arrays

Ferdinand_T_
New Contributor II
777 Views

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.

[fortran]

module m

    implicit none

contains

 

    ! 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

[/fortran]


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
Ferdinand

0 Kudos
1 Reply
Martin_D_1
Beginner
777 Views

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

0 Kudos
Reply