| 1 |
! { dg-do run } |
| 2 |
! PR fortran/107444 |
| 3 |
! |
| 4 |
! Check that procedures with optional arguments that have the value attribute |
| 5 |
! work for intrinsic types including character, and that the presence check |
| 6 |
! works. |
| 7 |
! |
| 8 |
! Co-contributed by M.Morin |
| 9 |
|
| 10 |
program p |
| 11 |
implicit none |
| 12 |
interface |
| 13 |
subroutine i(c, o) |
| 14 |
character(*) :: c |
| 15 |
character(3), optional, value :: o |
| 16 |
end subroutine i |
| 17 |
end interface |
| 18 |
procedure(i), pointer :: pp |
| 19 |
call s([.false.,.false.,.false.], 0) |
| 20 |
call s([.true., .false.,.false.], 10, i=7) |
| 21 |
call s([.false.,.true. ,.false.], 20, c='abc') |
| 22 |
call s([.false.,.false.,.true. ], 30, r=3.0) |
| 23 |
pp => f |
| 24 |
call pp ("abcd", "xyz") |
| 25 |
contains |
| 26 |
subroutine s (expect,code,i,c,r) |
| 27 |
logical, intent(in) :: expect(:) |
| 28 |
integer, intent(in) :: code |
| 29 |
integer , value, optional :: i |
| 30 |
character(3), value, optional :: c |
| 31 |
real , value, optional :: r |
| 32 |
if (expect(1) .neqv. present (i)) stop 1+code |
| 33 |
if (expect(2) .neqv. present (c)) stop 2+code |
| 34 |
if (expect(3) .neqv. present (r)) stop 3+code |
| 35 |
if (present (i)) then |
| 36 |
if (i /= 7) stop 4+code |
| 37 |
end if |
| 38 |
if (present (c)) then |
| 39 |
if (c /= "abc") stop 5+code |
| 40 |
end if |
| 41 |
if (present (r)) then |
| 42 |
if (r /= 3.0) stop 6+code |
| 43 |
end if |
| 44 |
end subroutine s |
| 45 |
subroutine f (c, o) |
| 46 |
character(*) :: c |
| 47 |
character(3), optional, value :: o |
| 48 |
if (c /= "abcd") stop 41 |
| 49 |
if (len (c) /= 4) stop 42 |
| 50 |
if (.not. present (o)) stop 43 |
| 51 |
if (o /= "xyz") stop 44 |
| 52 |
end subroutine f |
| 53 |
end |