From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id A3C2E3858401; Sun, 7 Nov 2021 11:01:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A3C2E3858401 From: "ygalklein at gmail dot com" 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 11.1.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: ygalklein at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 07 Nov 2021 11:01:13 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103115 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 =3D ["1"] titles =3D [titles,& "2",& "3",& "4",& "5"& ] block integer :: iTitle do iTitle =3D 1, size(titles) write(*, "('titles(',i2,') =3D ',a)") iTitle, trim(titles(iTitl= e)) end do end block end program reallocationCharacterArray ``` when compiled using gfortran 11.1 or 10.3 results with the following output: ` size(titles) =3D 5 titles( 1) =3D 1 titles( 2) =3D=20 titles( 3) =3D=20 titles( 4) =3D=20 titles( 5) =3D=20 ` 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 followi= ng output: ` size(titles) =3D 5 titles( 1) =3D 1 titles( 2) =3D 2 titles( 3) =3D 3 titles( 4) =3D 4 titles( 5) =3D 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 =3D ["1"] titles =3D [titles,& ! "2",& "3",& "4",& "5"& ] write(*, "('size(titles) =3D ',i1)") size(titles) block integer :: iTitle=20=20=20=20 do iTitle =3D 1, size(titles) write(*, "('titles(',i2,') =3D ',a)") iTitle, trim(titles(iTitl= e)) end do end block end program reallocationCharacterArray ``` results with the following right output: ` size(titles) =3D 4 titles( 1) =3D 1 titles( 2) =3D 3 titles( 3) =3D 4 titles( 4) =3D 5 ` both in gfortran and ifort.=