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

            Bug ID: 127541
           Summary: The type of array constructors can be polymorphic
           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: ---

Consider this testcase:

program prog
   implicit none
   type :: t1
      integer :: c1
   end type
   type, extends(t1) :: t2
      integer :: c2
   end type
   class(t1), allocatable :: x(:), y(:), z(:)
   x = [t2(2, 3), t2(5, 7)]
   y = [t2(11, 13), t2(17, 19)]
   print *, [x, y]
   z = [x, y]
   print *, storage_size(z)
   select type (z)
      type is (t1)
         print *, "OK"
      class default
         print *, "FAIL"
   end select
end program

This is rejected with:

   12 |    print *, [x, y]
      |                  1
Error: Data transfer element at (1) cannot be polymorphic unless it is
processed by a defined input/output procedure

It is questionable that the type of the array constructor is polymorphic.

F2023 (7.8 Construction of array values):
> If type-spec is omitted, corresponding length type parameters of the declared
> type of each ac-value expression shall have the same value; in this case, the
> declared type and type parameters of the array constructor are those of the
> ac-value expressions.
and one paragraph later:
> The dynamic type of an array constructor is the same as its declared type.

According to this, the type (both declared and dynamic type) of the array
constructor above is t1, despite x and y both having dynamic type of t2.
My question is: is it type(t1) or class(t1) with a dynamic type of t1?
In the former case the error is bogus; in the latter case it is not.

I tend to think the type is type(t1), so non-polymorphic, as the dynamic type
is not allowed to be different from the declared type.

Reply via email to