| 1 |
! Related to PR 19928. Check that foo() is only called once per statement. |
| 2 |
! { dg-do run } |
| 3 |
program main |
| 4 |
implicit none |
| 5 |
type t |
| 6 |
integer, dimension (5) :: field |
| 7 |
end type t |
| 8 |
type (t), dimension (2) :: a |
| 9 |
integer :: calls, i, j |
| 10 |
|
| 11 |
forall (i = 1:2, j = 1:5) a(i)%field(j) = i * 100 + j |
| 12 |
calls = 0 |
| 13 |
if (sum (a%field(foo(calls))) .ne. 304) STOP 1 |
| 14 |
if (calls .ne. 1) STOP 2 |
| 15 |
if (sum (a(foo(calls))%field) .ne. 1015) STOP 3 |
| 16 |
if (calls .ne. 2) STOP 4 |
| 17 |
contains |
| 18 |
function foo (calls) |
| 19 |
integer :: calls, foo |
| 20 |
calls = calls + 1 |
| 21 |
foo = 2 |
| 22 |
end function foo |
| 23 |
end program main |