1! { dg-do run }
2
3! Torture-test TRIM and LEN_TRIM for correctness.
4
5
6! Given a total string length and a trimmed length, construct an
7! appropriate string and check gfortran gets it right.
8
9SUBROUTINE check_trim (full_len, trimmed_len)
10  IMPLICIT NONE
11  INTEGER, INTENT(IN) :: full_len, trimmed_len
12  CHARACTER(LEN=full_len) :: string
13
14  string = ""
15  IF (trimmed_len > 0) THEN
16    string(trimmed_len:trimmed_len) = "x"
17  END IF
18
19  IF (LEN (string) /= full_len &
20      .OR. LEN_TRIM (string) /= trimmed_len &
21      .OR. LEN (TRIM (string)) /= trimmed_len &
22      .OR. TRIM (string) /= string (1:trimmed_len)) THEN
23    PRINT *, full_len, trimmed_len
24    PRINT *, LEN (string), LEN_TRIM (string)
25    CALL abort ()
26  END IF
27END SUBROUTINE check_trim
28
29
30! The main program, check with various combinations.
31
32PROGRAM main
33  IMPLICIT NONE
34  INTEGER :: i, j
35
36  DO i = 0, 20
37    DO j = 0, i
38      CALL check_trim (i, j)
39    END DO
40  END DO
41END PROGRAM main
42