summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/allocate_with_source_18.f03
blob: 746bd0ddd66d2554222e4dc1a9fb517cb3c5cd84 (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
! { dg-do run }
!
! PR fortran/57365
! [OOP] Sourced allocation fails with unlimited polymorphism
! Contributed by <rxs@hotmail.de>
!
program bug

    implicit none
    character(len=:), allocatable :: test

    test = "A test case"
    call allocate_test(test)
    deallocate(test)

contains

    subroutine allocate_test(var)
        class(*) :: var
        class(*), pointer :: copyofvar
        allocate(copyofvar, source=var)
        select type (copyofvar)
            type is (character(len=*))
!                print*, len(copyofvar), copyofvar
                if (len(copyofvar) /= 11) call abort ()
                if (copyofvar /= "A test case") call abort ()
        end select
        deallocate(copyofvar)
    end subroutine

end program bug