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

            Bug ID: 72709
           Summary: Incorrect assignment of allocatable character array
                    used as component of derived type
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zmi007 at gmail dot com
  Target Milestone: ---

In the following program the assignment to character array element doesn't work

program    read_exp_data
   implicit none

   type experimental_data_t
      integer :: nh = 0
      character(len=:), dimension(:), allocatable :: header

   end type experimental_data_t

   type(experimental_data_t) :: ex
   integer :: nh_len
   integer :: i


   nh_len = 255
   ex % nh = 3
   allocate(character(len=nh_len) :: ex % header(ex % nh))

   ex % header(1) = "#Generated by X"
   ex % header(2) = "#from file 'Y'"
   ex % header(3) = "# Experimental 4 mg/g"

   do i = 1, ex % nh
      write(*,*) "header(",i,") = ", ex % header(i)     
   enddo

end program read_exp_data

I get all 3 header elements = "# Experimental 4 mg/g"

gfortran --version
GNU Fortran (SUSE Linux) 6.1.1 20160707 [gcc-6-branch revision 238088]

---
bug disappears if one replaces appropriate strings with

character(len=255), dimension(:), allocatable :: header

and

allocate(ex % header(ex % nh))

Reply via email to