2012-03-27 23:13:14 +00:00
|
|
|
! { dg-do run }
|
|
|
|
! { dg-additional-sources bind_c_usage_24_c.c }
|
|
|
|
!
|
|
|
|
! PR fortran/48858
|
|
|
|
! PR fortran/48820
|
|
|
|
!
|
|
|
|
! TS 29113: BIND(C) with OPTIONAL
|
|
|
|
!
|
|
|
|
module m
|
|
|
|
use iso_c_binding
|
|
|
|
interface
|
|
|
|
subroutine c_proc (is_present, var) bind(C)
|
|
|
|
import
|
|
|
|
logical(c_bool), value :: is_present
|
|
|
|
integer(c_int), optional :: var
|
|
|
|
end subroutine
|
|
|
|
end interface
|
|
|
|
contains
|
|
|
|
subroutine subtest (is_present, var) bind(C)
|
|
|
|
logical(c_bool), intent(in), value :: is_present
|
|
|
|
integer(c_int), intent(inout), optional :: var
|
|
|
|
if (is_present) then
|
2018-12-28 15:30:48 +00:00
|
|
|
if (.not. present (var)) STOP 1
|
|
|
|
if (var /= 43) STOP 2
|
2012-03-27 23:13:14 +00:00
|
|
|
var = -45
|
|
|
|
else
|
2018-12-28 15:30:48 +00:00
|
|
|
if (present (var)) STOP 3
|
2012-03-27 23:13:14 +00:00
|
|
|
end if
|
|
|
|
end subroutine subtest
|
|
|
|
end module m
|
|
|
|
|
|
|
|
program test
|
|
|
|
use m
|
|
|
|
implicit none
|
|
|
|
integer :: val
|
|
|
|
|
|
|
|
val = 4
|
|
|
|
call c_proc (.false._c_bool)
|
|
|
|
call c_proc (.true._c_bool, val)
|
2018-12-28 15:30:48 +00:00
|
|
|
if (val /= 7) STOP 4
|
2012-03-27 23:13:14 +00:00
|
|
|
end program test
|