| 1 |
! { dg-do run } |
| 2 |
! PR 47065 - make sure that impure functions are not evaluated twice when |
| 3 |
! replacing calls to trim with expression(1:len_trim) |
| 4 |
module foo |
| 5 |
implicit none |
| 6 |
contains |
| 7 |
function f() |
| 8 |
integer :: f |
| 9 |
integer :: s=0 |
| 10 |
s = s + 1 |
| 11 |
f = s |
| 12 |
end function f |
| 13 |
end module foo |
| 14 |
|
| 15 |
program main |
| 16 |
use foo |
| 17 |
implicit none |
| 18 |
character(len=10) :: line |
| 19 |
character(len=4) :: b(2) |
| 20 |
b(1) = 'a' |
| 21 |
b(2) = 'bc' |
| 22 |
write(unit=line,fmt='(A,A)') trim(b(f())), "X" |
| 23 |
if (line /= "aX ") STOP 1 |
| 24 |
if (f() .ne. 2) STOP 2 |
| 25 |
end program main |