public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/103115] New: reallocation of character array fails when appending a constant size 4 array
@ 2021-11-07 11:01 ygalklein at gmail dot com
  2021-11-07 11:05 ` [Bug fortran/103115] " ygalklein at gmail dot com
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: ygalklein at gmail dot com @ 2021-11-07 11:01 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103115
           Summary: reallocation of character array fails when appending a
                    constant size 4 array
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ygalklein at gmail dot com
  Target Milestone: ---

The following example program:
```fortran
program reallocationCharacterArray
    implicit none
    character(:), dimension(:), allocatable :: titles
    titles = ["1"]
    titles = [titles,&
            "2",&
            "3",&
            "4",&
            "5"&
            ]
    block
        integer :: iTitle
        do iTitle = 1, size(titles)
            write(*, "('titles(',i2,') = ',a)") iTitle, trim(titles(iTitle))
        end do
    end block
end program reallocationCharacterArray
```

when compiled using gfortran 11.1 or 10.3 results with the following output:
`
size(titles) = 5
titles( 1) = 1
titles( 2) = 
titles( 3) = 
titles( 4) = 
titles( 5) = 
`

which is clearly wrong.
One can see that the reallocation succeded in increasing the size of titles
from 1 to 5 - but the assignment to all the places from 2 to 5 are erronous.

one should note that using intel compiler 2021.4 - results with the following
output:
`
size(titles) = 5
titles( 1) = 1
titles( 2) = 2
titles( 3) = 3
titles( 4) = 4
titles( 5) = 5
`

which is the right output.

One should also note that commenting one line from the constant array being
appended - i.e appending an array of size 3 (instead of size 4) results with
the right output when using gfortran, i.e

the following program (note the ! sign commenting one line):
```fortran
program reallocationCharacterArray
    implicit none
    character(:), dimension(:), allocatable :: titles
    titles = ["1"]
    titles = [titles,&
            ! "2",&
            "3",&
            "4",&
            "5"&
            ]
    write(*, "('size(titles) = ',i1)") size(titles)
    block
        integer :: iTitle    
        do iTitle = 1, size(titles)
            write(*, "('titles(',i2,') = ',a)") iTitle, trim(titles(iTitle))
        end do
    end block
end program reallocationCharacterArray
```

results with the following right output:
`
size(titles) = 4
titles( 1) = 1
titles( 2) = 3
titles( 3) = 4
titles( 4) = 5
`

both in gfortran and ifort.

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

end of thread, other threads:[~2023-05-08 12:23 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-07 11:01 [Bug fortran/103115] New: reallocation of character array fails when appending a constant size 4 array ygalklein at gmail dot com
2021-11-07 11:05 ` [Bug fortran/103115] " ygalklein at gmail dot com
2021-11-15 19:32 ` [Bug fortran/103115] [12 Regression] " tkoenig at gcc dot gnu.org
2021-11-16 12:29 ` juergen.reuter at desy dot de
2021-11-16 13:07 ` tkoenig at gcc dot gnu.org
2021-11-16 15:42 ` tkoenig at gcc dot gnu.org
2021-11-17  9:07 ` juergen.reuter at desy dot de
2021-11-17 16:30 ` tkoenig at gcc dot gnu.org
2022-01-17 13:00 ` rguenth at gcc dot gnu.org
2022-05-06  8:31 ` [Bug fortran/103115] [12/13 " jakub at gcc dot gnu.org
2023-05-08 12:23 ` [Bug fortran/103115] [12/13/14 " rguenth at gcc dot gnu.org

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).