2015-07-03 Christophe Lyon <christophe.lyon@linaro.org>
[official-gcc.git] / gcc / testsuite / gfortran.dg / alloc_comp_assign_14.f08
blob0fd4d91f0c174861d14943299767beb45f77c026
1 ! { dg-do run }
2 ! Test for allocatable scalar components and deferred length char arrays.
3 ! Check that fix for pr61275 works.
4 ! Contributed by Antony Lewis <antony@cosmologist.info> and
5 !                Andre Vehreschild <vehre@gmx.de>
7 module typeA
8     Type A
9         integer :: X
10         integer, allocatable :: y
11         character(len=:), allocatable :: c
12     end type A
13 end module
15 program test_allocatable_components
16     use typeA
17     Type(A) :: Me
18     Type(A) :: Ea
20     Me= A(X= 1, Y= 2, C="correctly allocated")
22     if (Me%X /= 1) call abort()
23     if (.not. allocated(Me%y) .or. Me%y /= 2) call abort()
24     if (.not. allocated(Me%c)) call abort()
25     if (len(Me%c) /= 19) call abort()
26     if (Me%c /= "correctly allocated") call abort()
28     ! Now check explicitly allocated components.
29     Ea%X = 9
30     allocate(Ea%y)
31     Ea%y = 42
32     ! Implicit allocate on assign in the next line
33     Ea%c = "13 characters"
35     if (Ea%X /= 9) call abort()
36     if (.not. allocated(Ea%y) .or. Ea%y /= 42) call abort()
37     if (.not. allocated(Ea%c)) call abort()
38     if (len(Ea%c) /= 13) call abort()
39     if (Ea%c /= "13 characters") call abort()
41     deallocate(Ea%y)
42     deallocate(Ea%c)
43     if (allocated(Ea%y)) call abort()
44     if (allocated(Ea%c)) call abort()
45 end program