https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91813
Bug ID: 91813
Summary: Derived types: Issues with user defined I/O and
recursive function of abstract type
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: m.diehl at mpie dot de
Target Milestone: ---
Created attachment 46896
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=46896&action=edit
Example code with user defined I/O (not working)
This bug is a hard to describe because it seems to results from a strange side
condition.
In brief, I have a abstract base class (tNode) and two derived classes (tScalar
and tList) which are used to build a tree-structure from a YAML file. This is
done with a recursive function which parses a string and has the class of the
abstract type:
recursive function YAML_parse(str) result(parsed)
class(tNode), allocatable :: parsed
character(len=*), intent(in) :: str
type(tList) :: li
integer :: e, s
if (str(1:1) == '[') then
e = 1
do while (e < len(str))
s = e
e = s + find_end(str(s+1:))
call li%append(YAML_parse(str(s+1:e-1))) ! Bug in Gfortran:
This call to parse allocates parsed
enddo
allocate(parsed,source=li) ! error message
appears here
else
parsed = tScalar(trim(str))
endif
end function
The function fails at the allocation with the message "'parsed' is already
allocated" even though this statement is called only once in each function
call. My guess is that there is a mix-up of YAML_parse and parsed (note that
the 'result' style is mandatory) due to the recursive invocation.
Now the strange thing: This happens only if the types have user defined I/O.
I.e. if line 8, 26, and 37 (and subsequently 108-148 and 163) are commented out
the code works to the extend that there is no run time error. Unfortunately, in
that case I can not easily figure out if the values are stored appropriately.
I'm running arch linux on a 64bit Intel i7
Note that bug 88768 migh be related.