https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77358
Bug ID: 77358
Summary: [F08] deferred-length character function returns
zero-length string
Product: gcc
Version: 7.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: damian at sourceryinstitute dot org
Target Milestone: ---
As shown below with gfotran 7.0, a deferred-length character function returns a
zero-length string when the function is implemented inside a submodule. Either
of the following eliminates the bug:
(1) moving the function from the submodule to the module or
(2) changing the deferred-length character declarations to fixed-length
declarations with or without the allocatable attribute.
It would be great if the fix could be back ported to the 6 branch.
$ cat alloc-char-func-in-submodule.f90
module hello_interface
character(len=13) :: string="Hello, world!"
interface
module function get() result(result_string)
character(:), allocatable :: result_string
end function
end interface
end module
submodule(hello_interface) hello_implementation
contains
module function get() result(result_string)
character(:), allocatable :: result_string
result_string = string
end function
end submodule
use hello_interface
print *,len(get())
end
$ gfortran alloc-char-func-in-submodule.f90
$ ./a.out
0
$ gfortran --version
GNU Fortran (MacPorts gcc7 7-20160814_0) 7.0.0 20160814 (experimental)