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

            Bug ID: 126519
           Summary: Actual rank of an assumed rank dummy incorrect if the
                    actual arg is an absent optional
           Product: gcc
           Version: 17.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: mikael at gcc dot gnu.org
  Target Milestone: ---

Example passing an absent optional to an (optional) assumed rank dummy:

program p
  implicit none
  type :: t1
    integer :: c1
  end type
  call check_wrapper()
contains
  subroutine check_wrapper(a)
    class(t1), optional :: a(:)
    call check_rank(a)
  end subroutine
  subroutine check_rank(a)
    class(t1), optional :: a(..)
    print *, rank(a)
    select rank (a)
      rank(1)
        print *, "OK"
      rank default
        print *, "FAIL"
    end select
  end subroutine
end program

It prints at runtime:
           0
 FAIL

I would expect instead:
           1
 OK

It may seem questionable to ask for the rank of an argument ultimately
associated to nothing, but I think this is valid.  There is an intermediary
dummy argument between the "nothing" and the assumed rank, and that
intermediary makes it possible to guess the rank.

Reply via email to