------- Comment #3 from fxcoudert at gcc dot gnu dot org 2007-03-19 09:05 ------- Created an attachment (id=13229) --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13229&action=view) Patch that fixes the issue reported
The attached patch fixes the issue for the reported testcase. I checked that we still issue errors when the optional parameter is present and has the wrong size; the code below will error out as expected if one of the commented lines is uncommented: 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() call sub((/4,5/)) ! call sub((/4/)) ! call sub((/4,5,6/)) end program main Anyway, the other calls to checking routines need to be audited for similar problems with optional args. That probably includes making a testcase for each situation, and see if optional arg can be used in each context. -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31119