| 1 |
! { dg-do run } |
| 2 |
! { dg-additional-sources "optional-c.c dump-descriptors.c" } |
| 3 |
! { dg-additional-options "-g" } |
| 4 |
! |
| 5 |
! TS 29113 |
| 6 |
! 8.7 An absent actual argument in a reference to an interoperable |
| 7 |
! procedure is indicated by a corresponding formal parameter with the |
| 8 |
! value of a null pointer. An absent optional dummy argument in a |
| 9 |
! reference to an interoperable procedure from a C function is indicated |
| 10 |
! by a corresponding argument with the value of a null pointer. |
| 11 |
|
| 12 |
module m |
| 13 |
use iso_c_binding |
| 14 |
integer(C_INT) :: aa(32) |
| 15 |
integer(C_INT) :: bb |
| 16 |
character(C_CHAR) :: cc |
| 17 |
real(C_DOUBLE) :: dd |
| 18 |
end module |
| 19 |
|
| 20 |
subroutine ftest (n, a, b, c, d) bind (c) |
| 21 |
use iso_c_binding |
| 22 |
use m |
| 23 |
implicit none |
| 24 |
integer(C_INT), value :: n |
| 25 |
integer(C_INT), optional :: a(:) |
| 26 |
integer(C_INT), optional :: b |
| 27 |
character(C_CHAR), optional :: c |
| 28 |
real(C_DOUBLE), optional :: d |
| 29 |
|
| 30 |
if (n .ge. 1) then |
| 31 |
if (.not. present (a)) stop 101 |
| 32 |
if (any (a .ne. aa)) stop 201 |
| 33 |
else |
| 34 |
if (present (a)) stop 301 |
| 35 |
end if |
| 36 |
|
| 37 |
if (n .ge. 2) then |
| 38 |
if (.not. present (b)) stop 102 |
| 39 |
if (b .ne. bb) stop 201 |
| 40 |
else |
| 41 |
if (present (b)) stop 302 |
| 42 |
end if |
| 43 |
|
| 44 |
if (n .ge. 3) then |
| 45 |
if (.not. present (c)) stop 103 |
| 46 |
if (c .ne. cc) stop 201 |
| 47 |
else |
| 48 |
if (present (c)) stop 303 |
| 49 |
end if |
| 50 |
|
| 51 |
if (n .ge. 4) then |
| 52 |
if (.not. present (d)) stop 104 |
| 53 |
if (d .ne. dd) stop 201 |
| 54 |
else |
| 55 |
if (present (d)) stop 304 |
| 56 |
end if |
| 57 |
end subroutine |
| 58 |
|
| 59 |
program testit |
| 60 |
use iso_c_binding |
| 61 |
use m |
| 62 |
implicit none |
| 63 |
|
| 64 |
interface |
| 65 |
subroutine ctest1 (a, b, c, d) bind (c) |
| 66 |
use iso_c_binding |
| 67 |
integer(C_INT) :: a(:) |
| 68 |
integer(C_INT) :: b |
| 69 |
character(C_CHAR) :: c |
| 70 |
real(C_DOUBLE) :: d |
| 71 |
end subroutine |
| 72 |
subroutine ctest2 (n, a, b, c, d) bind (c) |
| 73 |
use iso_c_binding |
| 74 |
integer(C_INT), value :: n |
| 75 |
integer(C_INT), optional :: a(:) |
| 76 |
integer(C_INT), optional :: b |
| 77 |
character(C_CHAR), optional :: c |
| 78 |
real(C_DOUBLE), optional :: d |
| 79 |
end subroutine |
| 80 |
subroutine ftest (n, a, b, c, d) bind (c) |
| 81 |
use iso_c_binding |
| 82 |
integer(C_INT), value :: n |
| 83 |
integer(C_INT), optional :: a(:) |
| 84 |
integer(C_INT), optional :: b |
| 85 |
character(C_CHAR), optional :: c |
| 86 |
real(C_DOUBLE), optional :: d |
| 87 |
end subroutine |
| 88 |
end interface |
| 89 |
|
| 90 |
|
| 91 |
! Initialize the variables above. |
| 92 |
integer :: i |
| 93 |
do i = 1, 32 |
| 94 |
aa(i) = i |
| 95 |
end do |
| 96 |
bb = 42 |
| 97 |
cc = '$' |
| 98 |
dd = acos(-1.D0) |
| 99 |
|
| 100 |
call ftest (0) |
| 101 |
call ftest (1, aa) |
| 102 |
call ftest (2, aa, bb) |
| 103 |
call ftest (3, aa, bb, cc) |
| 104 |
call ftest (4, aa, bb, cc, dd) |
| 105 |
|
| 106 |
call ctest1 (aa, bb, cc, dd) |
| 107 |
call ctest2 (0) |
| 108 |
call ctest2 (1, aa) |
| 109 |
call ctest2 (2, aa, bb) |
| 110 |
call ctest2 (3, aa, bb, cc) |
| 111 |
call ctest2 (4, aa, bb, cc, dd) |
| 112 |
|
| 113 |
end program |
| 114 |
|