https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106317
Bug ID: 106317 Summary: deferred-length character array pointer in derived type Product: gcc Version: 11.3.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: clange001 at gmail dot com Target Milestone: --- The following test program gives seg fault with fortran 11.3. I'm trying to store a pointer to a deferred-length character array. The pointer I'd like to store is in a derived type. A regular fortran intrinsic pointer outside of the derived type works fine, but a pointer stored in the derived type does not. My apologies if this has been addressed or reported elsewhere. $ gfortran --version GNU Fortran (MacPorts gcc11 11.3.0_1) 11.3.0 Copyright (C) 2021 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. $ cat test.f90 program test type t character(:), pointer, dimension(:) :: a_ptr end type type(t) :: mt character(:), pointer, dimension(:) :: a character(:), pointer, dimension(:) :: b_ptr allocate(character(len=10) :: a(3)) a(:) = '0123456789' print *, a ! this works fine b_ptr => a print *, associated(b_ptr, a) print *, b_ptr ! does not seem work if pointer is member of derived type mt%a_ptr => a print *, associated(mt%a_ptr, a) print *, len(mt%a_ptr) ! string length is NOT correct print *, size(mt%a_ptr) ! array size IS correct print *, mt%a_ptr ! seg fault trying to access print *, 'end' end program test $ gfortran test.f90 $ ./a.out 012345678901234567890123456789 T 012345678901234567890123456789 T 328630909 3 Program received signal SIGSEGV: Segmentation fault - invalid memory reference. Backtrace for this error: #0 0x10b2f4590 #1 0x10b2f3c1e #2 0x7fff205b5d7c #3 0x10b42d2c5 #4 0x10b430664 #5 0x10b4310bb #6 0x10b2e0cfd #7 0x10b2e0dc6 zsh: segmentation fault ./a.out