| 1 |
! { dg-do run } |
| 2 |
! Tests the fix for PR31867, in which the interface evaluation |
| 3 |
! of the character length of 'join' (ie. the length available in |
| 4 |
! the caller) was wrong. |
| 5 |
! |
| 6 |
! Contributed by <[email protected]> |
| 7 |
! |
| 8 |
module util_mod |
| 9 |
implicit none |
| 10 |
contains |
| 11 |
function join (words, sep) result(str) |
| 12 |
character (len=*), intent(in) :: words(:),sep |
| 13 |
character (len = (size (words) - 1) * len_trim (sep) + & |
| 14 |
sum (len_trim (words))) :: str |
| 15 |
integer :: i,nw |
| 16 |
nw = size (words) |
| 17 |
str = "" |
| 18 |
if (nw < 1) then |
| 19 |
return |
| 20 |
else |
| 21 |
str = words(1) |
| 22 |
end if |
| 23 |
do i=2,nw |
| 24 |
str = trim (str) // trim (sep) // words(i) |
| 25 |
end do |
| 26 |
end function join |
| 27 |
end module util_mod |
| 28 |
! |
| 29 |
program xjoin |
| 30 |
use util_mod, only: join |
| 31 |
implicit none |
| 32 |
integer yy |
| 33 |
character (len=5) :: words(5:8) = (/"two ","three","four ","five "/), sep = "^#^" |
| 34 |
character (len=5) :: words2(4) = (/"bat ","ball ","goal ","stump"/), sep2 = "&" |
| 35 |
|
| 36 |
if (join (words, sep) .ne. "two^#^three^#^four^#^five") STOP 1 |
| 37 |
if (len (join (words, sep)) .ne. 25) STOP 2 |
| 38 |
|
| 39 |
if (join (words(5:6), sep) .ne. "two^#^three") STOP 3 |
| 40 |
if (len (join (words(5:6), sep)) .ne. 11) STOP 4 |
| 41 |
|
| 42 |
if (join (words(7:8), sep) .ne. "four^#^five") STOP 5 |
| 43 |
if (len (join (words(7:8), sep)) .ne. 11) STOP 6 |
| 44 |
|
| 45 |
if (join (words(5:7:2), sep) .ne. "two^#^four") STOP 7 |
| 46 |
if (len (join (words(5:7:2), sep)) .ne. 10) STOP 8 |
| 47 |
|
| 48 |
if (join (words(6:8:2), sep) .ne. "three^#^five") STOP 9 |
| 49 |
if (len (join (words(6:8:2), sep)) .ne. 12) STOP 10 |
| 50 |
|
| 51 |
if (join (words2, sep2) .ne. "bat&ball&goal&stump") STOP 11 |
| 52 |
if (len (join (words2, sep2)) .ne. 19) STOP 12 |
| 53 |
|
| 54 |
if (join (words2(1:2), sep2) .ne. "bat&ball") STOP 13 |
| 55 |
if (len (join (words2(1:2), sep2)) .ne. 8) STOP 14 |
| 56 |
|
| 57 |
if (join (words2(2:4:2), sep2) .ne. "ball&stump") STOP 15 |
| 58 |
if (len (join (words2(2:4:2), sep2)) .ne. 10) STOP 16 |
| 59 |
|
| 60 |
end program xjoin |