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

            Bug ID: 97037
           Summary: ICE on user-defined derived-type output of an
                    intermediate ancestor type
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: damian at sourceryinstitute dot org
  Target Milestone: ---

The code below effectively has an abstract parent type ("object"), abstract
child type ("oracle"), and a non-abstract grandchild type ("results_t") in
which the parent has a derived-type output binding, the child has a type-bound
operator(-) associated with a deferred binding ("negative"), and the grandchild
implements both deferred bindings.  An ICE results when attempting to write the
result of the operator.  Presumably the issue is that the grandchild's operator
result must be of the child type.  The child type inherits the derived-type
output binding from the parent, but it doesn't itself explicitly state such a
binding. I lean toward thinking the code is valid, but I haven't yet consulted
the standard.

$ cat uddtio-ice.f90 
module object_interface
  implicit none

  type, abstract :: object
  contains
    procedure(write_formatted_interface), deferred :: write_formatted
    generic :: write(formatted) => write_formatted
  end type

  abstract interface
    subroutine write_formatted_interface(this, unit, iotype, vlist, iostat,
iomsg)
      import object
      implicit none
      class(object), intent(in) :: this
      integer, intent(in) :: unit, vlist(:)
      character(len=*), intent(in) :: iotype
      integer, intent(out) :: iostat
      character(len=*), intent(inout) :: iomsg
    end subroutine
  end interface

  type, abstract, extends(object) :: oracle
  contains
    procedure(negative_interface), deferred :: negative
    generic :: operator(-) => negative
  end type

  abstract interface
    function negative_interface(this)
      import oracle
      implicit none
      class(oracle), intent(in) :: this
      class(oracle), allocatable :: negative_interface
    end function
  end interface

  type, extends(oracle) :: results_t
  contains
    procedure write_formatted
    procedure negative
  end type

  interface
    module subroutine write_formatted(this, unit, iotype, vlist, iostat, iomsg)
      implicit none
      class(results_t), intent(in) :: this
      integer, intent(in) :: unit, vlist(:)
      character(len=*), intent(in) :: iotype
      integer, intent(out) :: iostat
      character(len=*), intent(inout) :: iomsg
    end subroutine
    module function negative(this)
      implicit none
      class(results_t), intent(in) :: this
      class(oracle), allocatable :: negative
    end function
  end interface
end module

  use object_interface
  write(*,*) -results_t()
end program

$ gfortran -c uddtio-ice.f90 
uddtio-ice.f90:61:0:

   61 |   write(*,*) -results_t()
      | 
internal compiler error: Segmentation fault: 11

$ gfortran --version
GNU Fortran (GCC) 11.0.0 20200804 (experimental)

Reply via email to