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

            Bug ID: 116706
           Summary: Unable to fill allocatable array component of a
                    derived type instance in a pointer array within a
                    derived type
           Product: gcc
           Version: 14.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: baradi09 at gmail dot com
  Target Milestone: ---

* Issue:

GIVEN
a derived type containing a pointer array of a derived type with an allocatable
array component

WHEN
the pointer array is allocated and an array is assigned to the allocatable
array component of the first element

THEN
the program segfaults (or gives a dubious error message when compiled in debug
mode)


* Minimal working example

program testprog
  implicit none

  type :: data_node
    integer, allocatable :: data(:)
  end type data_node

  type :: data_list
    type(data_node), pointer :: nodes(:) => null()
  end type data_list

  type(data_list) :: datalist
  allocate(datalist%nodes(3))
  datalist%nodes(1)%data = [1, 2, 3]

end program testprog


* Compiling

gfortran -Og -g3 -fbounds-check ~/ramdisk/bugdemo.f90


* Observed behavior

> ./a.out
At line 14 of file [...]/bugdemo.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'datalist'
(1/3)

Error termination. Backtrace:
#0  0x55e596dc0344 in testprog
        at [...]/bugdemo.f90:14
#1  0x55e596dc0371 in main
        at [...]/bugdemo.f90:16


* Expected behavior

Code should run through without problems


* Notes

- when the allocatable component data is a scalar, and not an array (and the
assignment is changed accordingly), the program runs as expected

- when the array "nodes(:)" is turned into an allocatable array, the program
runs as expected.

- when an array similar to "nodes(:)" is created outside of a derived type as a
stand-alone array, the program runs as expected.

Reply via email to