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

            Bug ID: 94599
           Summary: Invalid constructor for derived types with recursive
                    allocatable components
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pault at gcc dot gnu.org
  Target Milestone: ---

Created attachment 48271
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=48271&action=edit
A kludge to fix the problem

module m

   type :: stack_t
      integer :: index
      type(stack_t), allocatable :: payload
      type(stack_t), allocatable :: next
   end type stack_t
end module

   use m

   type (stack_t) :: start
   print *, allocated(start%payload), allocated(start%next)

   start = stack_t(index=42) ! Should provide NULL for both 'payload' and
'next'

   print *, allocated(start%payload), allocated(start%next)

end

should output
 F F
 F F

but, instead, outputs
 F F
 F T

The reason for this is apparent on compilation with the option
-fdump-parse-tree.

   start = stack_t(index=42) generates

  ASSIGN MAIN__:start stack_t(42 , () , stack_t(() , NULL()))

The appearance of the constructor for the 'next' component is wrong. It should
be NULL(), since this is a missing component in the constructor. (F2018: 7.5.10
Construction of derived-type values)

Note that 'payload' is correct. Any number of subsequent components of the
parent type are incorrect.

I cannot see, at present, what the problem is caused by. Evidently, somewhere,
the default_initializer is applied.

The attached is a kludge that fixes the problem and regtests OK but is
incorrect.

Paul

Reply via email to