possible bug for function returning derived type (trunk binaries)

Paul Richard Thomas paul.richard.thomas@gmail.com
Sun Jan 11 12:16:00 GMT 2009


Dear Marco,

Many thanks for this report.  A temporary workaround is not to use
RESULT for a_fun.  This works:

module mod_a
 type t_1
  real :: coeff
 end type t_1
 type t_2
  type(t_1), allocatable :: mons(:)
 end type t_2
contains
 function a_fun(r)
 integer, intent(in) :: r
 type(t_2) :: a_fun(r+1)  !!!!!!!!!!!!!!!!!!!!!
 write(*,*) 'shape(p) is ', shape(a_fun)
 end function a_fun
end module mod_a


program test
 use mod_a, only: a_fun, t_1, t_2
 implicit none
 type(t_2) x(1)
 x = a_fun(0)
end program test

I am just going to file a PR on it.

I wonder if, since you are becoming a regular, you could please start
filing you reports in Bugzilla?  It would be very helpful to us since
even the few minutes spent doing it is time lost to fixing things:-(

Cheers

Paul

On Sat, Jan 10, 2009 at 10:54 AM, marco restelli <mrestelli@gmail.com> wrote:
> Dear all,
>   the attached code produces a segmentation fault with the latest
> trunk binaries. The code looks fine to me, and it runs with ifort and
> g95.
>
> Best regards,
>   Marco Restelli
>
>
> $ gfortran test.f90 -o test
> $ ./test
> Segmentation fault
>
> $ gfortran --version
> GNU Fortran (GCC) 4.4.0 20090110 (experimental) [trunk revision 143243]
>
> System:
> Linux 2.6.23-gentoo-r6 x86_64 AMD Turion(tm) 64 Mobile Technology
> ML-32 AuthenticAMD GNU/Linux
>
>
> module mod_a
>  implicit none
>  public :: a_fun, t_1, t_2
>  private
>
>  type t_1
>   real :: coeff
>  end type t_1
>
>  type t_2
>   type(t_1), allocatable :: mons(:)
>  end type t_2
>
> contains
>
>  function a_fun(r) result(p)
>  integer, intent(in) :: r
>
>  type(t_2) :: p(r+1)
>  ! Using an allocatable works
>  !type(t_2), allocatable :: p(:)
>  ! allocate(p(r+1))
>
>  write(*,*) 'shape(p) is ', shape(p)
>
>  end function a_fun
>
> end module mod_a
>
>
> program test
>  use mod_a, only: a_fun, t_1, t_2
>  implicit none
>  type(t_2) x(1)
>
>  x = a_fun(0)
> end program test
>



-- 
The knack of flying is learning how to throw yourself at the ground and miss.
       --Hitchhikers Guide to the Galaxy



More information about the Fortran mailing list