https://gcc.gnu.org/bugzilla/show_bug.cgi?id=63205
paul.richard.thomas at gmail dot com <paul.richard.thomas at gmail dot com>
changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #33834|0 |1
is obsolete| |
--- Comment #4 from paul.richard.thomas at gmail dot com <paul.richard.thomas
at gmail dot com> ---
Created attachment 33995
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=33995&action=edit
Patch that fixes testcase in the comment but causes regressions.
The attached patch runs the testcase below without memory leaks but causes
regressions in:
class_allocate_7.f03
class_to_type_2.f90
typebound_operator_7.f03
typebound_operator_8.f03
All of these are run time errors caused by finalization occurring too soon. The
additions to gfc_conv_procedure_call will have to be moved to
gfc_trans_assignment_1 so that the specific case of class function assignment
to derived type is caught. I will attend to this during this week.
Paul
program test
implicit none
type t
integer :: ii
end type t
type, extends(t) :: u
real :: rr
end type u
type, extends(t) :: v
real, allocatable :: rr(:)
end type v
type, extends(v) :: w
real, allocatable :: rrr(:)
end type w
type(t) :: x, y(3)
type(v) :: a, b(3)
x = func1() ! scalar to scalar - no alloc comps
print *, x%ii
y = func2() ! array to array - no alloc comps
print *, y%ii
y = func1() ! scalar to array - no alloc comps
print *, y%ii
x = func3() ! scalar daughter type to scalar - no alloc comps
print *, x%ii
y = func4() ! array daughter type to array - no alloc comps
print *, y%ii
a = func5() ! scalar to scalar - alloc comps in parent type
print *, a%rr
b = func6() ! array to array - alloc comps in parent type
print *, b(3)%rr
a = func7() ! scalar daughter type to scalar - alloc comps in parent type
print *, a%rr
b = func8() ! array daughter type to array - alloc comps in parent type
print *, b(3)%rr
contains
function func1() result(res)
class(t), allocatable :: res
allocate (res, source = t(77))
end function func1
function func2() result(res)
class(t), allocatable :: res(:)
allocate (res(3), source = [u(1,1.0),u(2,2.0),u(3,3.0)])
end function func2
function func3() result(res)
class(t), allocatable :: res
allocate (res, source = v(99,[99.0,99.0,99.0]))
end function func3
function func4() result(res)
class(t), allocatable :: res(:)
allocate (res(3), source = [v(3,[1.0,2.0]),v(4,[2.0,3.0]),v(5,[3.0,4.0])])
end function func4
function func5() result(res)
class(v), allocatable :: res
allocate (res, source = v(3,[10.0,20.0]))
end function func5
function func6() result(res)
class(v), allocatable :: res(:)
allocate (res(3), source = [v(3,[1.0,2.0]),v(4,[2.0,3.0]),v(5,[3.0,4.0])])
end function func6
function func7() result(res)
class(v), allocatable :: res
allocate (res, source = w(3,[10.0,20.0],[100,200]))
end function func7
function func8() result(res)
class(v), allocatable :: res(:)
allocate (res(3), source =
[w(3,[1.0,2.0],[0.0]),w(4,[2.0,3.0],[0.0]),w(5,[3.0,4.0],[0.0])])
end function func8
end program test