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

            Bug ID: 96992
           Summary: Class arrays of different ranks are rejected as
                    storage association argument
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tkoenig at gcc dot gnu.org
  Target Milestone: ---

The following program is wrongly rejected.  I don't find anything
wrong with it from my reading of the F2018 standard. This is classic
sequence association, as defined in 15.5.2.11 of F2018:

# An actual argument that represents an element sequence and
# corresponds to a dummy argument that is an array is sequence
# associated with the dummy argument. The rank and shape of the
# actual argument need not agree with the rank and shape of the
# dummy argument, but the number of elements in the dummy argument
# shall not exceed the number of elements in the element sequence
# of the actual argument. If the dummy argument is assumed-size,
# the number of elements in the dummy argument is exactly
# the number of elements in the element sequence.

module foo_mod
  implicit none
  type foo
     integer :: i
  end type foo
contains
  subroutine d1(x,n)
    integer, intent(in) :: n
    class (foo), intent(out), dimension(n) :: x
    select type(x)
    class is(foo)
       x%i = 42
    class default
       stop "Bad crazyness"
    end select
  end subroutine d1
  subroutine d2(x,n)
    integer, intent(in) :: n
    class (foo), intent(in), dimension(n,n) :: x
    select type (x)
    class is (foo)
       print *,x%i
    class default
       stop "Even worse crazyness"
    end select
  end subroutine d2
end module foo_mod
program main
  use foo_mod
  implicit none
  type (foo), dimension(:), allocatable :: f
  integer :: n
  n = 3
  allocate (f(n*n))
  call d1(f,n*n)
  call d2(f,n)
end program main

Reply via email to