| 1 |
! { dg-do compile } |
| 2 |
! { dg-options "-pedantic-errors" } |
| 3 |
! |
| 4 |
! Contributed by Martin Diehl <[email protected]> |
| 5 |
|
| 6 |
program elemental_optional |
| 7 |
implicit none |
| 8 |
integer :: m(5), r(5) |
| 9 |
|
| 10 |
m = 1 |
| 11 |
|
| 12 |
r = outer() |
| 13 |
r = outer(m) |
| 14 |
|
| 15 |
contains |
| 16 |
|
| 17 |
function outer(o) result(l) |
| 18 |
integer, intent(in), optional :: o(:) |
| 19 |
integer :: u(5), l(5) |
| 20 |
|
| 21 |
l = inner(o,u) |
| 22 |
|
| 23 |
end function outer |
| 24 |
|
| 25 |
function outer_literal(o) result(l) |
| 26 |
integer, intent(in), optional :: o(5) |
| 27 |
integer :: l(5) |
| 28 |
|
| 29 |
l = inner(o, [1,2,3,4,5]) |
| 30 |
end function outer_literal |
| 31 |
|
| 32 |
function outer_func(o) result(l) |
| 33 |
integer, intent(in), optional :: o(5) |
| 34 |
integer :: l(5) |
| 35 |
|
| 36 |
l = inner(o, outer()) |
| 37 |
end function outer_func |
| 38 |
|
| 39 |
elemental function inner(a,b) result(x) |
| 40 |
integer, intent(in), optional :: a |
| 41 |
integer, intent(in) :: b |
| 42 |
integer :: x |
| 43 |
|
| 44 |
if(present(a)) then |
| 45 |
x = a*b |
| 46 |
else |
| 47 |
x = b |
| 48 |
endif |
| 49 |
end function inner |
| 50 |
|
| 51 |
end program elemental_optional |
| 52 |
|