Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28459 Discussions

compile failure for recursive derived type input-output

Cristian_P_
Beginner
289 Views

WARNING: If the code below does not compile immediately, please Ctrl-C fast; otherwise, huge cores are being produced, and you may have to restart your workstation. 

! Code from Figure 19.3 on page 324 of "Fortran 95/2003 explained"

! IFORT 15.0.1 compiles the code, and the program runs fine.

! IFORT 16.0.0 never returns from compilation; Ctrl-C causes 
! huge core files to be created

Module list_module
   Implicit None

   Type node
      Integer              :: value = 0
      Class(node), Pointer :: next_node => Null()
   Contains
      Procedure :: pwf
      Generic   :: Write(Formatted) => pwf
   End Type node

Contains

   Recursive Subroutine pwf(dtv, unit, iotype, vlist, iostat, iomsg)
      Class(node), Intent(In)     :: dtv
      Integer, Intent(In)         :: unit
      Character(*), Intent(In)    :: iotype
      Integer, Intent(In)         :: vlist(:)
      Integer, Intent(Out)        :: iostat
      Character(*), Intent(InOut) :: iomsg

      Character(10)                :: pfmt

      Write(unit, fmt = '(i9,/)', iostat = iostat) dtv%value
      If(iostat /= 0) return
      If(Associated(dtv%next_node)) Write(unit, fmt='(dt)', iostat=iostat) dtv%next_node
   End Subroutine pwf

End Module list_module

Program test
   Use list_module
   Implicit None

   Type(node), Target :: first_link = node(42, Null())
   Type(node), Target :: second_link = node(43, Null())
   Type(node), Target :: third_link = node(44, Null())

   first_link%next_node  => second_link
   second_link%next_node => third_link

   Print '(dt)', first_link

End Program test

 

0 Kudos
2 Replies
Steven_L_Intel1
Employee
289 Views

Thanks - I can reproduce this and escalated as issue DPD200381365. The key seems to be the component that is a pointer to its own type - if that is removed, it compiles. I suspect that the compiler is now trying to chase down the tree when it shouldn't, but I'll wait to see what the developers say.

0 Kudos
Steven_L_Intel1
Employee
289 Views

Indeed, this is a bug that snuck in while we were redoing some code. I expect it to be fixed in Update 3.

0 Kudos
Reply