2017-02-20 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / c_loc_tests_11.f03
blobd009ce09652e8d463646e5214541a3ad569abcaf
1 ! { dg-do compile }
2 ! { dg-options "-std=f2008" }
4 ! Test argument checking for C_LOC with subcomponent parameters.
5 module c_vhandle_mod
6   use iso_c_binding
7   
8   type double_vector_item
9     real(kind(1.d0)), allocatable :: v(:)
10   end type double_vector_item
11   type(double_vector_item), allocatable, target :: dbv_pool(:)
12   real(kind(1.d0)), allocatable, target :: vv(:)
14   type foo
15      integer :: i
16   end type foo
17   type foo_item
18      type(foo), pointer  :: v => null()
19   end type foo_item
20   type(foo_item), allocatable :: foo_pool(:)
22   type foo_item2
23      type(foo), pointer  :: v(:) => null()
24   end type foo_item2
25   type(foo_item2), allocatable :: foo_pool2(:)
28 contains 
30   type(c_ptr) function get_double_vector_address(handle)
31     integer(c_int), intent(in) :: handle
32     
33     if (.true.) then   ! The ultimate component is an allocatable target 
34       get_double_vector_address = c_loc(dbv_pool(handle)%v)  ! OK: Interop type and allocatable
35     else
36       get_double_vector_address = c_loc(vv)  ! OK: Interop type and allocatable
37     endif
38     
39   end function get_double_vector_address
42   type(c_ptr) function get_foo_address(handle)
43     integer(c_int), intent(in) :: handle    
44     get_foo_address = c_loc(foo_pool(handle)%v)
46     get_foo_address = c_loc(foo_pool2(handle)%v) ! { dg-error "TS 29113/TS 18508: Noninteroperable array at .1. as argument to C_LOC: Expression is a noninteroperable derived type" }
47   end function get_foo_address
49     
50 end module c_vhandle_mod