Bug 31148 - optional argument of elemental function
Summary: optional argument of elemental function
Status: RESOLVED DUPLICATE of bug 31119
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-03-12 15:41 UTC by Vivek Rao
Modified: 2007-03-18 17:49 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vivek Rao 2007-03-12 15:41:13 UTC
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
Comment 1 Francois-Xavier Coudert 2007-03-18 17:49:16 UTC
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 ***