From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 61A7E3854812; Wed, 2 Jun 2021 20:53:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 61A7E3854812 From: "thomas.robinson at noaa dot gov" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/100886] New: Variable character pointer within a Fortran derived type can't determine the shape(mold) of the target Date: Wed, 02 Jun 2021 20:53:26 +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: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: thomas.robinson at noaa dot gov 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: Wed, 02 Jun 2021 20:53:26 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D100886 Bug ID: 100886 Summary: Variable character pointer within a Fortran derived type can't determine the shape(mold) of the target Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: thomas.robinson at noaa dot gov Target Milestone: --- A character pointer within a Fortran DDT can't determine the shape(mold) of= a variable length allocatable target character array Desired behavior: DDT pointer behaves like a non-DDT pointer and properly determines shape(mold) of the target and points to it Here is some sample code: program char_ptr_test implicit none character(len=3D:), dimension(:), allocatable, target:: input_nml_file character(len=3D:), dimension(:), pointer:: copy_input_nml_file =3D> null() type init_type character(len=3D:), dimension(:), pointer:: input_nml_file =3D> null() end type init_type type(init_type):: Init integer:: i character(len=3D6):: arg logical:: gnu=3D.false. !--- parse command line call get_command_argument(1, arg) if (len_trim(arg) > 0) print *, trim(arg) !--- set up input_nml_file and output the result call init_input() do i =3D 1,size(input_nml_file) print *, 'Main input_nml_file is: "',input_nml_file(i),'"' enddo !--- plain pointer - works as expected print *, NEW_LINE('a'),'plain pointer' copy_input_nml_file =3D> input_nml_file do i =3D 1,size(copy_input_nml_file) print *, 'copy_input_nml_file is: "',copy_input_nml_file(i),'"' enddo nullify(copy_input_nml_file) !--- pointer within a DDT - fails !--- point to input_nml_file elements (:) print *, NEW_LINE('a'),'pointer within fortran ddt @ elements (:)' Init%input_nml_file =3D> input_nml_file(:) do i =3D 1,size(Init%input_nml_file) print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"' enddo !--- pointer within a DDT - fails !--- point to input_nml_file as whole print *, NEW_LINE('a'),'pointer within fortran ddt @ whole entity' Init%input_nml_file =3D> input_nml_file do i =3D 1,size(Init%input_nml_file) print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"' enddo nullify(Init%input_nml_file) !--- pointer within a DDT - works !--- point to input_nml_file elements (:) !--- allocate/deallocate to get shape print *, NEW_LINE('a'),'pointer within fortran ddt with shape settings @ elements(:)' allocate(Init%input_nml_file, mold=3Dinput_nml_file) deallocate(Init%input_nml_file) Init%input_nml_file =3D> input_nml_file(:) do i =3D 1,size(Init%input_nml_file) print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"' enddo nullify(Init%input_nml_file) !--- pointer within a DDT - fails with segfault !--- point to input_nml_file as whole !--- allocate/deallocate to get shape print *, NEW_LINE('a'),'pointer within fortran ddt w/ shape settings @ wh= ole entity' allocate(Init%input_nml_file, mold=3Dinput_nml_file) deallocate(Init%input_nml_file) Init%input_nml_file =3D> input_nml_file do i =3D 1,size(Init%input_nml_file) print *, 'Init%input_nml_file is: "',Init%input_nml_file(i),'"' enddo nullify(Init%input_nml_file) contains subroutine init_input() allocate(character(len=3D10)::input_nml_file(7)) input_nml_file(1) =3D 'New York ' input_nml_file(2) =3D 'London ' input_nml_file(3) =3D 'Paris ' input_nml_file(4) =3D 'Munich ' input_nml_file(5) =3D 'Everybody ' input_nml_file(6) =3D 'talk about' input_nml_file(7) =3D 'Pop Muzik ' end subroutine init_input end program char_ptr_test The behavior is different between 9.3 and 10.2, but the same for 10.2 to 12= .0 (at least for the versions that I have available). Please let me know if there's any other information you need=