public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "ygalklein at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/103115] New: reallocation of character array fails when appending a constant size 4 array
Date: Sun, 07 Nov 2021 11:01:13 +0000	[thread overview]
Message-ID: <bug-103115-4@http.gcc.gnu.org/bugzilla/> (raw)

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.

             reply	other threads:[~2021-11-07 11:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-07 11:01 ygalklein at gmail dot com [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103115-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).