[Bug fortran/79230] [7 Regression] [OOP] Run time error: double free or corruption
vehre at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Jan 28 18:29:00 GMT 2017
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79230
--- Comment #18 from vehre at gcc dot gnu.org ---
Correct me when I am wrong, but should the pointer component really be
finalized automatically? I am in the opinion that pointer components are not
finalized automatically. That is one of the significant differences to
allocatable components. I am thinking about a single linked list, where one
does:
type link
type(link), pointer :: next
class(*) :: data
end type
Grant me the above to be pseudo-fortran to just explain the concept.
Now, when I want to delete only the first item of the list and have:
type (link), pointer :: head
type (link), pointer :: newhead => head%next
deallocate(head) ! This one would deallocate the whole list, when finalization
is done!
So I first need to do:
head%next => NULL
deallocate(head)
which for a pointer is IMHO not the intention of the standard. When I like to
have managed memory with full automatic free, then one should have chosen
allocatable, or am I totally misunderstanding Fortran?
More information about the Gcc-bugs
mailing list