https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113377

--- Comment #4 from anlauf at gcc dot gnu.org ---
(In reply to anlauf from comment #3)
> However,
> 
>     integer, allocatable,optional :: j
> 
> still does not work: the code *in* the generated loop looks fine to me, but
> the scalarizer dereferences j before the loop.

Note that the following scalar example also fails:

program p
  implicit none
  integer :: k = 1
  call one (k)
contains
  subroutine one (i, j)
    integer, intent(in)           :: i
!   integer             ,optional :: j
    integer, allocatable,optional :: j
    if (present (j)) error stop "j is present"
    call two (i, j)
  end

  elemental subroutine two (i, j)
    integer, intent(in)           :: i
!   integer, value,      optional :: j
    integer, intent(in), optional :: j
    if (present (j)) error stop 99
  end
end

In subroutine one the if-statement is properly translated, but "call two"
mishandles the optional argument j when it is allocatable.

Reply via email to