https://gcc.gnu.org/bugzilla/show_bug.cgi?id=64120
--- Comment #13 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to Jürgen Reuter from comment #12)
> Paul, getting back to this one? At first glance seems not overly much work
> left for the remaining case.
Hi Juergen,
I am in the midst of a triage of my assigned PRs and, this time, I started at
the oldest. There always seems to be an urgency associated with the most recent
because the reporters usually press for a fix in the weeks or months after
posting.
If 's' is declared thus:
character(x), allocatable, save :: s
it produces the error
Error: Automatic object ‘s’ at (1) cannot have the SAVE attribute
It seems to me that what is true for an explicit save is true for an implicit
one too and that the second testcase is invalid.
Either that or the automatic length should switch off the implicit save
attribute.
Note that this version works as expected:
program test
logical :: L
L = g(1)
write(*,*) L
L = g(2)
write(*,*) L
L = g(4)
write(*,*) L
L = g(1)
write(*,*) L
contains
logical function g(x)
integer :: x
character(:), allocatable :: s
save
if(.NOT.allocated(s)) then
allocate(character(len=x) :: s)
s='x'
g = .FALSE.
elseif (x .eq. 4) then
s = 'abcd'
else
g = .TRUE.
end if
write(*,*) "len(s)=", len(s), "s=", s
end function g
end
[pault@pc30 69654]$ ./a.out
len(s)= 1 s=x
F
len(s)= 1 s=x
T
len(s)= 4 s=abcd
T
len(s)= 4 s=abcd
T
That is, a deferred character length respects the save attribute, whereas an
automatic length cannot.
What do you think?
Paul