[Bug fortran/78848] [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure

2016-12-18 Thread mikael at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78848

Mikael Morin  changed:

   What|Removed |Added

 CC||mikael at gcc dot gnu.org

--- Comment #6 from Mikael Morin  ---
No ICE here at r243465.

[Bug fortran/78848] [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure

2016-12-18 Thread janus at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78848

--- Comment #5 from janus at gcc dot gnu.org ---
BTW, I suspect the ICE might be a regression introduced by r243609 (my fix for
PR 78737).

[Bug fortran/78848] [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure

2016-12-18 Thread janus at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78848

--- Comment #4 from janus at gcc dot gnu.org ---
Sorry, actually the example in comment 3 only ICEs if the type-binding of the
DTIO is commented out:

module m
  type :: t
integer :: i
  contains
! procedure :: wf
! generic :: write(formatted) => wf
  end type
  interface write(formatted)
procedure wf
  end interface
contains
  subroutine wf(this, unit, b, c, iostat, iomsg)
class(t), intent(in) :: this
integer, intent(in) :: unit
character, intent(in) :: b
integer, intent(in) :: c(:)
integer, intent(out) :: iostat
character, intent(inout) :: iomsg
  WRITE (unit, "(i3)", IOSTAT=iostat, IOMSG=iomsg) this%i
  end subroutine
end

program p
  use m
  class(t), allocatable :: z
  allocate(z)
  print *, z
end

[Bug fortran/78848] [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure

2016-12-18 Thread janus at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78848

janus at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||ice-on-valid-code

--- Comment #3 from janus at gcc dot gnu.org ---
(In reply to Jerry DeLisle from comment #2)
> I think its invalid in that the type contains no object that could be
> written or even allocated.

I think empty types are valid in principle, but that's not the point. Here is a
slightly expanded test case (with a non-empty type) that should actually print
something. Still it ICEs:

module m
  type :: t
integer :: i
  contains
procedure :: wf
generic :: write(formatted) => wf
  end type
  interface write(formatted)
procedure wf
  end interface
contains
  subroutine wf(this, unit, b, c, iostat, iomsg)
class(t), intent(in) :: this
integer, intent(in) :: unit
character, intent(in) :: b
integer, intent(in) :: c(:)
integer, intent(out) :: iostat
character, intent(inout) :: iomsg
  WRITE (unit, "(i3)", IOSTAT=iostat, IOMSG=iomsg) this%i
  end subroutine
end

program p
  use m
  class(t), allocatable :: z
  allocate(z)
  print *, z
end

[Bug fortran/78848] [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure

2016-12-17 Thread jvdelisle at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78848

Jerry DeLisle  changed:

   What|Removed |Added

 CC||jvdelisle at gcc dot gnu.org

--- Comment #2 from Jerry DeLisle  ---
I think its invalid in that the type contains no object that could be written
or even allocated. Or at least the example makes no sense to me. Regardless it
ICEs so should it be an error, i dont know what it should say?

"Attempting to use an empty type" or "baseless type"

or if it is valid, it should compile nothing since there is nothing to print
with print *, z. What is it allocating? NIL?

[Bug fortran/78848] [OOP] ICE on writing CLASS variable with non-typebound DTIO procedure

2016-12-17 Thread janus at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78848

--- Comment #1 from janus at gcc dot gnu.org ---
Also one can wonder what kind of code should be generated here.

When using the type-bound form of the DTIO procedure, we generate a truly
polymorphic reference to the DTIO procedure when printing a CLASS variable,
i.e. z._vptr->wf in our example. This was implemented in PR 78737.

If we have no typebound DTIO procedure, but rather a non-typebound one, we
cannot do that, so we probably have to call the DTIO procedure in a
non-polymorphic fashion (based on the declared type), as if we were printing a
TYPE variable (?).