http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58557
Bug ID: 58557 Summary: [OOP] Issues with CLASS/TYPE functions in array constructors: reject valid, memory leaks, invalid free Product: gcc Version: 4.9.0 Status: UNCONFIRMED Keywords: rejects-valid, wrong-code Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: burnus at gcc dot gnu.org The following test case shows that functions which return derived-types/polymorphic arrays are mishandled. Failures: * For many: Error: Can't convert REAL(4) to TYPE(t) * For instance: *(atmp[0].data) = *f_type() ! ups null pointer deref * Memory not freed for funcs returning allocatable memory. Note: One problem is that the functions can occur in nested constructors, ac-do loops, having unknown ac-do loop bounds array sizes. program main implicit none type t end type t interface function f_type() import :: t type(t), allocatable :: f_type end function f_type function f_type_na() import :: t type(t) :: f_type end function f_type_na function f_type_array() import :: t type(t), allocatable :: f_type(:) end function f_type_array function f_type_array_na() import :: t type(t) :: f_type(5) end function f_type_array_na function f_class(i) import :: t class(t), allocatable :: f_class integer :: i end function f_class function f_class_array() import :: t class(t), allocatable :: f_class integer :: i end function f_class_array subroutine sub_type2(x) import :: t type(t) :: x(:) end subroutine sub_type2 subroutine sub_class2(x) import :: t class(t) :: x(:) end subroutine sub_class2 end interface type(t) :: b(1) integer :: i b = [ f_type() ] b = [ f_type_na() ] b = [ f_type_array() ] b = [ f_type_array_na() ] b = [ f_class_array(1) ] call sub_type2([f_class(1)]) call sub_type2([f_class_array(1)]) call sub_type2([(f_class(i),i=1,5)]) call sub_type2([(f_class_array(i),i=1,5)]) call sub_class2([f_class(1)]) call sub_class2([f_class_array(1)]) call sub_class2([(f_class(i),i=1,5)]) call sub_class2([(f_class_array(i),i=1,5)]) end program main