2017-12-08 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / testsuite / gfortran.dg / alloc_comp_initializer_1.f90
blobac37fd6e38973cef2ce1d036d95099681ee56f3f
1 ! { dg-do run }
2 ! This checks the correct functioning of derived types with default initializers
3 ! and allocatable components.
5 ! Contributed by Salvatore Filippone <salvatore.filippone@uniroma2.it>
7 module p_type_mod
9 type m_type
10 integer, allocatable :: p(:)
11 end type m_type
13 type basep_type
14 type(m_type), allocatable :: av(:)
15 type(m_type), pointer :: ap => null ()
16 integer :: i = 101
17 end type basep_type
19 type p_type
20 type(basep_type), allocatable :: basepv(:)
21 integer :: p1 , p2 = 1
22 end type p_type
23 end module p_type_mod
25 program foo
27 use p_type_mod
28 implicit none
30 type(m_type), target :: a
31 type(p_type) :: pre
32 type(basep_type) :: wee
34 call test_ab8 ()
36 a = m_type ((/101,102/))
38 call p_bld (a, pre)
40 if (associated (wee%ap) .or. wee%i /= 101) call abort ()
41 wee%ap => a
42 if (.not.associated (wee%ap) .or. allocated (wee%av)) call abort ()
43 wee = basep_type ((/m_type ((/201, 202, 203/))/), null (), 99)
44 if (.not.allocated (wee%av) .or. associated (wee%ap) .or. (wee%i .ne. 99)) call abort ()
46 contains
48 ! Check that allocatable components are nullified after allocation.
49 subroutine test_ab8 ()
50 type(p_type) :: p
51 integer :: ierr
53 if (.not.allocated(p%basepv)) then
54 allocate(p%basepv(1),stat=ierr)
55 endif
56 if (allocated (p%basepv) .neqv. .true.) call abort ()
57 if (allocated (p%basepv(1)%av) .neqv. .false.) call abort
58 if (p%basepv(1)%i .ne. 101) call abort ()
60 end subroutine test_ab8
62 subroutine p_bld (a, p)
63 use p_type_mod
64 type (m_type) :: a
65 type(p_type) :: p
66 if (any (a%p .ne. (/101,102/))) call abort ()
67 if (allocated (p%basepv) .or. (p%p2 .ne. 1)) call abort ()
68 end subroutine p_bld
70 end program foo