From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19989 invoked by alias); 10 Aug 2015 16:35:56 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 19956 invoked by uid 48); 10 Aug 2015 16:35:52 -0000 From: "templed at tcd dot ie" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/67177] New: MOVE_ALLOC not automatically allocating deferred character arrays in derived types Date: Mon, 10 Aug 2015 16:35:00 -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: 5.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: templed at tcd dot ie 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: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-08/txt/msg00656.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67177 Bug ID: 67177 Summary: MOVE_ALLOC not automatically allocating deferred character arrays in derived types Product: gcc Version: 5.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: templed at tcd dot ie Target Milestone: --- (First time submitting a bug, apologies if I've messed up somewhere) When a derived type containing a deferred-length character variable is the TO= argument of a MOVE_ALLOC() call the character length is not correctly set and the value of the variable is not stored. Two workarounds for this is to either not use deferred-length character variables (use an allocatable array of single characters), or to preallocate the length to the variable that will be the TO= argument. The below test program has been tested with Intel 15.0.2 (20150121) and, when the line critical line is commented out (see code) the program correctly allocates the deferred-length string and populates it with the correct value. In gfortran 5.2 (and 4.9.2, FWIW) it fails to allocate the length and store the value even though a check with allocated() returns true. $ gfortran -v Using built-in specs. COLLECT_GCC=gfortran COLLECT_LTO_WRAPPER=/usr/support/modules/gnu-5.2/libexec/gcc/x86_64-unknown-linux-gnu/5.2.0/lto-wrapper Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/usr/support/modules/gnu-5.2 --disable-multilib Thread model: posix gcc version 5.2.0 (GCC) Test program: program str implicit none type string character(:), Allocatable :: text end type string type strings type(string), allocatable, dimension(:) :: strlist end type strings type(strings) :: teststrs type(string) :: tmpstr integer :: strlen = 20 allocate(teststrs%strlist(1)) allocate(character(len=strlen) :: tmpstr%text) ! This is the critical line. If this is commented then ! the move_alloc fails. Whereas what should happen is that ! this variable should be allocated automatically by move_alloc allocate(character(len=strlen) :: teststrs%strlist(1)%text) ! Needs blanking otherwise memory is leaked tmpstr%text(1:20) = ' ' tmpstr%text(1:3) = 'foo' ! Should return "alloc?, strlen F 20" when the critical line is commented out (shows 'T' otherwise) write(*,*)'alloc?, strlen ',allocated(teststrs%strlist(1)%text),len(tmpstr%text) call move_alloc(tmpstr%text,teststrs%strlist(1)%text) ! Should return "alloc?, strlen T 20" write(*,*)'alloc?, strlen ',allocated(teststrs%strlist(1)%text),len(teststrs%strlist(1)%text) ! Should return "foo " write(*,*)'"',teststrs%strlist(1)%text,'"' end program str