| 1 |
! { dg-do compile } |
| 2 |
! { dg-options "-std=f2003" } |
| 3 |
! PR fortran/84924 |
| 4 |
! Testcase contributed by Seth Johnson <[email protected]> |
| 5 |
! |
| 6 |
module ftest |
| 7 |
use ISO_C_BINDING |
| 8 |
implicit none |
| 9 |
|
| 10 |
type :: Cls |
| 11 |
end type |
| 12 |
|
| 13 |
type :: ClsHandle |
| 14 |
class(Cls), pointer :: ptr |
| 15 |
end type |
| 16 |
contains |
| 17 |
subroutine to_ptr(c, p) |
| 18 |
use ISO_C_BINDING |
| 19 |
class(Cls), intent(in), target :: c |
| 20 |
type(C_PTR), intent(out) :: p |
| 21 |
type(ClsHandle), pointer :: handle |
| 22 |
allocate(handle) |
| 23 |
handle%ptr => c |
| 24 |
p = c_loc(handle) |
| 25 |
end subroutine |
| 26 |
|
| 27 |
subroutine from_ptr(p, c) |
| 28 |
use ISO_C_BINDING |
| 29 |
type(C_PTR), intent(in) :: p |
| 30 |
class(Cls), intent(out), pointer :: c |
| 31 |
type(ClsHandle), pointer :: handle |
| 32 |
call c_f_pointer(cptr=p, fptr=handle) |
| 33 |
c => handle%ptr |
| 34 |
deallocate(handle) |
| 35 |
end subroutine |
| 36 |
end module |