public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/94599] New: Invalid constructor for derived types with recursive allocatable components
@ 2020-04-14 18:15 pault at gcc dot gnu.org
  2020-07-21 14:32 ` [Bug fortran/94599] " dominiq at lps dot ens.fr
  0 siblings, 1 reply; 2+ messages in thread
From: pault at gcc dot gnu.org @ 2020-04-14 18:15 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug fortran/94599] Invalid constructor for derived types with recursive allocatable components
  2020-04-14 18:15 [Bug fortran/94599] New: Invalid constructor for derived types with recursive allocatable components pault at gcc dot gnu.org
@ 2020-07-21 14:32 ` dominiq at lps dot ens.fr
  0 siblings, 0 replies; 2+ messages in thread
From: dominiq at lps dot ens.fr @ 2020-07-21 14:32 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-07-21
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
Confirmed from at least GCC7.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-07-21 14:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14 18:15 [Bug fortran/94599] New: Invalid constructor for derived types with recursive allocatable components pault at gcc dot gnu.org
2020-07-21 14:32 ` [Bug fortran/94599] " dominiq at lps dot ens.fr

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).