Since ivec is not passed to sub, I think the two calls to set_optional should be equivalent, but gfortran crashes upon the second call. u:\vrao\fortran type xopt_bug.f90 module sub_mod contains elemental subroutine set_optional(i,idef,iopt) ! set i to (iopt,idef) if iopt (is,is not) PRESENT integer, intent(out) :: i integer, intent(in) :: idef integer, intent(in), optional :: iopt if (present(iopt)) then i = iopt else i = idef end if end subroutine set_optional ! subroutine sub(ivec) integer , intent(in), optional :: ivec(:) integer :: ivec_(2) call set_optional(ivec_,(/1,2/)) print*,"ivec_=",ivec_ call set_optional(ivec_,(/1,2/),ivec) print*,"ivec_=",ivec_ end subroutine sub end module sub_mod program main use sub_mod, only: sub call sub() end program main U:\vrao\fortran>gfortran -v Using built-in specs. Target: i386-pc-mingw32 Configured with: ../trunk/configure --prefix=/mingw --enable-languages=c,fortran --with-gmp=/home/coudert/local --disable-nls --with-ld=/mingw/bin/ld --with-as=/mingw/bin/as --disable-werror --enable-bootstrap --enable-threads --host=i386-pc-mingw32 --disable-shared --enable-libgomp Thread model: win32 gcc version 4.3.0 20061021 (experimental) U:\vrao\fortran>gfortran -W -Wall -pedantic-errors -std=f2003 -fbounds-check -Werror xopt_bug.f90 U:\vrao\fortran>a.exe Fortran runtime error: Array bound mismatch, size mismatch for dimension 1 of array 'ivec' (in file 'xopt_bug.f90', at line 20) ivec_= 1 2
Summary of what other compilers do: - gfortran-compiled code runs OK without -fbounds-check, issue runtime error with -fbounds-check - intel-compiled code runs OK, but segfaults with -check all - sun-compiled code segfaults whether you use -C or not - g95 runs OK with and without checking I think it's a gfortran -fbounds-check bug, and it seems to be a duplicate of PR 31119. <FX looks to be sure. He realizes it's the exact same code. Stupid me, should have looked earlier.> *** This bug has been marked as a duplicate of 31119 ***