It seems that not a pointer is transferred but a value in the following case.
Here is the tracking info:

gfortran -g fptr_transfer.f90 -o fptr_transfer && ./fptr_transfer
Segmentation fault (core dumped)gdb fptr_transfer core
[...]
Program terminated with signal 11, Segmentation fault.
#0  0x0000000000400629 in assign_proc_ptr (ptr=0x0, obj1=( 0x40060c <proc> 
)) at fptr_transfer.f90:32
32          ptr => obj1%proc
(gdb) where
#0  0x0000000000400629 in assign_proc_ptr (ptr=0x0, obj1=( 0x40060c <proc> 
)) at fptr_transfer.f90:32
#1  0x0000000000400687 in transfer_proc_ptr (obj2=( 0 ), obj1=( 0x40060c 
<proc> )) at fptr_transfer.f90:26
#2  0x000000000040064c in foo () at fptr_transfer.f90:19
#3  0x00000000004006c2 in main (argc=1, argv=0x7ffff12d2fe4 
'./fptr_transfer\000') at fptr_transfer.f90:19
#4  0x00007f1d9cdf0586 in __libc_start_main () from /lib64/libc.so.6
#5  0x0000000000400549 in _start () at ../sysdeps/x86_64/elf/start.S:113
Current language:  auto; currently fortran
(gdb)

Here is the corresponding code:
subroutine proc ()
end subroutine proc

program foo

   interface
      subroutine proc ()
      end subroutine proc
   end interface

   type :: container_t
      procedure(proc), nopass, pointer :: proc => null ()
   end type container_t

   type(container_t), target :: obj1
   type(container_t) :: obj2

   obj1%proc => proc
   call transfer_proc_ptr (obj2, obj1)

contains

   subroutine transfer_proc_ptr (obj2, obj1)
     type(container_t), intent(out) :: obj2
     type(container_t), intent(in), target :: obj1
     call assign_proc_ptr (obj2%proc, obj1)
   end subroutine transfer_proc_ptr

   subroutine assign_proc_ptr (ptr, obj1)
     procedure(proc), pointer :: ptr
     type(container_t), intent(in), target :: obj1
     ptr => obj1%proc
   end subroutine assign_proc_ptr

end program foo


-- 
           Summary: [4.5.0] problem with procedure pointers
           Product: gcc
           Version: 4.5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: fortran
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: reuter at physik dot uni-freiburg dot de
 GCC build triplet: Ref. svn r150253
  GCC host triplet: Linux 32bit, 64bit, MAC OS X
GCC target triplet: fortran 4.5.0


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=41022

Reply via email to