2017-02-20 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / trim_optimize_6.f90
blob2303bb4ef78b0192b133e98ee21a22793dff288b
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
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 ") call abort
24 if (f() .ne. 2) call abort
25 end program main