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

            Bug ID: 127258
           Summary: Polymorphic actual argument association with a
                    non-polymorphic pointer dummy is accepted
           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: ---

Testcase:

program prog
  implicit none
  type :: t1
    integer :: c1
  end type
  type(t1), pointer :: p(:)
  class(t1), pointer :: x(:)
  allocate(x(5))
  call sub(x)
  deallocate(x)
contains
  subroutine sub(arg)
    type(t1), pointer :: arg(:)
  end subroutine
end program

This is accepted by gfortran, but is invalid.
The actual argument x is polymporphic, whereas the associated dummy is
non-polymorphic.

>From F2023 (15.5.2.6 Allocatable and pointer dummy variables):
 > The actual argument shall be polymorphic if and only if the associated dummy
 > argument is polymorphic, and either both the actual and dummy arguments
shall
 > be unlimited polymorphic, or the declared type of the actual argument shall
 > be the same as the declared type of the dummy argument.

and in the note just below:
 > Dynamic type information is not maintained for a nonpolymorphic allocatable
 > or pointer dummy argument. However, allocating or pointer-assigning such a
 > dummy argument would require maintenance of this information if the
 > corresponding actual argument is polymorphic. Therefore, the corresponding
 > actual argument needs to be nonpolymorphic.

Reply via email to