http://gcc.gnu.org/bugzilla/show_bug.cgi?id=49110
--- Comment #10 from John <jwmwalrus at gmail dot com> 2011-05-22 19:36:33 UTC
---
(In reply to comment #9)
> Note the routine need not be pure to invoke the segfault. Here's
> an even shorter test case.
>
> program foo
> implicit none
> character s(5)
> s = ['a', 'b', 'c', 'd', 'e']
> print *, bar(s)
> contains
> function bar(s) result(a)
> ! character, intent(in) :: s(5) ! Compiles and runs
> character, intent(in) :: s(:) ! Compiles and segfaults
> character(len=:), allocatable :: a
> a = repeat('a', size(s))
> end function bar
> end program foo
My bug report is actually about the fact that the "pure" attribute triggers an
(incorrect) error, and that error is associated to the deferred-length
character result. The code compiles just fine by removing the "pure" attribute
from the original code... Or by changing "character(:), allocatable :: string"
to something like "character(2047) :: string".
So I guess the subject line is fine.
The reason why I used interoperability with C, is because the module is just a
reduced version of the actual, practical case that triggered the error ---sorry
if it's "garbage" to you.