aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/deferred_type_param_8.f90
blob: 3c768c567a7485bcc4883d3b7a9152b4238936a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
! { dg-do run }
!
! PR fortran/53642
! PR fortran/45170 (comments 24, 34, 37)
!

PROGRAM helloworld
  implicit none
  character(:),allocatable::string
  character(11), parameter :: cmp = "hello world"
  real::rnd
  integer :: n, i
  do i = 1, 10
     call random_number(rnd)
     n = ceiling(11*rnd)
     call hello(n, string)
!     print '(A,1X,I0)', '>' // string // '<', len(string)
     if (n /= len (string) .or. string /= cmp(1:n)) call abort ()
  end do

  call test_PR53642()

contains

  subroutine hello (n,string)
    character(:), allocatable, intent(out) :: string
    integer,intent(in) :: n
    character(11) :: helloworld="hello world"

    string=helloworld(:n)                       ! Didn't  work
!    string=(helloworld(:n))                    ! Works.
!    allocate(string, source=helloworld(:n))    ! Fixed for allocate_with_source_2.f90
!    allocate(string, source=(helloworld(:n)))  ! Works.
  end subroutine hello

  subroutine test_PR53642()
    character(len=4) :: string="123 "
    character(:), allocatable :: trimmed

    trimmed = trim(string)
    if (len_trim(string) /= len(trimmed)) call abort ()
    if (len(trimmed) /= 3) call abort ()
    if (trimmed /= "123") call abort ()
!    print *,len_trim(string),len(trimmed)

    ! Clear
    trimmed = "XXXXXX"
    if (trimmed /= "XXXXXX" .or. len(trimmed) /= 6) call abort ()

    trimmed = string(1:len_trim(string))
    if (len_trim(trimmed) /= 3) call abort ()
    if (trimmed /= "123") call abort ()
  end subroutine test_PR53642
end PROGRAM helloworld