| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Test the fix for PR65677, in which the dependency was missed and |
| 4 |
! the string length of 'text' was decremented twice. The rhs string |
| 5 |
! length is now fixed after the function call so that the dependency |
| 6 |
! on the length of 'text' is removed for later evaluations. |
| 7 |
! |
| 8 |
!Contributed by John <[email protected]> |
| 9 |
! |
| 10 |
module mod1 |
| 11 |
implicit none |
| 12 |
contains |
| 13 |
subroutine getKeyword(string, keyword, rest, use_adjustl) |
| 14 |
character(:), allocatable, intent(IN) :: string |
| 15 |
character(:), allocatable, intent(OUT) :: keyword, rest |
| 16 |
integer :: idx |
| 17 |
character(:), allocatable :: text |
| 18 |
logical :: use_adjustl |
| 19 |
|
| 20 |
keyword = '' |
| 21 |
rest = '' |
| 22 |
text = string |
| 23 |
if (use_adjustl) then |
| 24 |
text = ADJUSTL(text(2:)) ! Note dependency. |
| 25 |
else |
| 26 |
text = text(2:) ! Check the old workaround. |
| 27 |
endif |
| 28 |
idx = INDEX(text, ' ') |
| 29 |
|
| 30 |
if (idx == 0) then |
| 31 |
keyword = TRIM(text) |
| 32 |
else |
| 33 |
keyword = text(:idx-1) |
| 34 |
rest = TRIM(ADJUSTL(text(idx+1:))) |
| 35 |
endif |
| 36 |
end subroutine |
| 37 |
end module mod1 |
| 38 |
|
| 39 |
use mod1 |
| 40 |
implicit none |
| 41 |
|
| 42 |
character(:), allocatable :: line, keyword, rest |
| 43 |
|
| 44 |
line = '@HERE IT IS' |
| 45 |
|
| 46 |
call getKeyword(line, keyword, rest, use_adjustl = .true.) |
| 47 |
|
| 48 |
if (keyword .ne. 'HERE') stop 1 |
| 49 |
if (rest .ne. 'IT IS') stop 2 |
| 50 |
deallocate (line, keyword, rest) |
| 51 |
|
| 52 |
line = '@HERE IT IS' |
| 53 |
|
| 54 |
call getKeyword(line, keyword, rest, use_adjustl = .false.) |
| 55 |
|
| 56 |
if (keyword .ne. 'HERE') stop 3 |
| 57 |
if (rest .ne. 'IT IS') stop 4 |
| 58 |
deallocate (line, keyword, rest) |
| 59 |
end |