3 ! Tests the fix for PR44265. This is the original test with the addition
4 ! of the check of the issue found in comment #1 of the PR.
6 ! Contributed by Ian Harvey <ian_harvey@bigpond.com>
7 ! Ian also contributed the first version of the fix.
9 ! The original version of the bug
15 FUNCTION Get0(i
) RESULT(s
)
16 CHARACTER(*), PARAMETER :: names(3) = [ &
20 INTEGER, INTENT(IN
) :: i
21 CHARACTER(LEN_TRIM(names(i
))) :: s
27 ! Version that came about from sorting other issues.
31 character (20) :: buffer
32 CHARACTER(*), PARAMETER :: names(4) = [ &
37 PUBLIC
:: Get
, SGet
, fruity2
, fruity3
, buffer
39 ! This worked previously
41 write (buffer
, '(i2,a)') len (Get (4)), Get (4)
43 ! Original function in the PR
44 FUNCTION Get(i
) RESULT(s
)
45 INTEGER, INTENT(IN
) :: i
46 CHARACTER(LEN_trim(names(i
))) :: s
50 ! Check that dummy is OK
52 CHARACTER(*), PARAMETER :: names(4) = [ &
57 INTEGER, INTENT(IN
) :: i
58 CHARACTER(LEN_trim(names(i
))), intent(out
) :: s
61 write (buffer
, '(i2,a)') len (s
), s
63 ! This would fail with undefined references to mangled 'names' during linking
65 write (buffer
, '(i2,a)') len (Get (3)), Get (3)
69 PROGRAM WheresThatbLinkingConstantGone
73 character(7) :: arg
= ""
76 ! Test the fix for the original bug
77 if (len (Get0(1)) .ne
. 5) STOP 1
78 if (Get0(2) .ne
. "Orange") STOP 2
80 ! Test the fix for the subsequent issues
82 if (trim (buffer
) .ne
. " 6Orange") STOP 3
84 if (trim (buffer
) .ne
. " 5Mango") STOP 4
86 if (trim (buffer
) .ne
. " 4Pear") STOP 5
90 if (trim (buffer
) .ne
. " 5Mango") STOP 6
91 if (trim (arg
) .ne
. "Mango") STOP 7
93 if (trim (buffer
) .ne
. " 4Pear") STOP 8
94 ! Since arg is fixed length in this scope, it gets over-written
95 ! by s, which in this case is length 4. Thus, the 'o' remains.
96 if (trim (arg
) .ne
. "Pearo") STOP 9
101 write (buffer
, '(i2,a)') len (Get (2)), Get (2)
103 END PROGRAM WheresThatbLinkingConstantGone