This is the mail archive of the
fortran@gcc.gnu.org
mailing list for the GNU Fortran project.
Bug 77358 - [F08] deferred-length character function returns zero-length string
- From: Damian Rouson <damian at sourceryinstitute dot org>
- To: gfortran <fortran at gcc dot gnu dot org>
- Cc: Paul Richard Thomas <paul dot richard dot thomas at gmail dot com>, Tom Clune <thomas dot l dot clune at nasa dot gov>, Brad King <brad dot king at kitware dot com>
- Date: Tue, 23 Aug 2016 18:05:21 -0700
- Subject: Bug 77358 - [F08] deferred-length character function returns zero-length string
- Authentication-results: sourceware.org; auth=none
I just submitted the following text in the above referenced bug report.
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 backported 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)
Damian