summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/alloc_comp_default_init_1.f90
blob: 48947cd2e666fcf9aac3923e4fec0b459141b8fe (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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
! { dg-do run }
! Checks the fixes for PR34681 and PR34704, in which various mixtures
! of default initializer and allocatable array were not being handled
! correctly for derived types with allocatable components.
!
! Contributed by Paolo Giannozzi <p.giannozzi@fisica.uniud.it>
!
program boh
  integer :: c1, c2, c3, c4, c5
  !
  call mah (0, c1) ! These calls deal with PR34681
  call mah (1, c2)
  call mah (2, c3)
  !
  if (c1 /= c2) call abort
  if (c1 /= c3) call abort
  !
  call mah0 (c4) ! These calls deal with PR34704
  call mah1 (c5)
  !
  if (c4 /= c5) call abort
  !
end program boh
!
subroutine mah (i, c)
  !
  integer, intent(in) :: i
  integer, intent(OUT) :: c
  !
  type mix_type
     real(8), allocatable :: a(:)
     complex(8), allocatable :: b(:)
  end type mix_type
  type(mix_type), allocatable, save :: t(:)
  integer :: j, n=1024
  !
  if (i==0) then
     allocate (t(1))
     allocate (t(1)%a(n))
     allocate (t(1)%b(n))
     do j=1,n
        t(1)%a(j) = j
        t(1)%b(j) = n-j
     end do
  end if
  c = sum( t(1)%a(:) ) + sum( t(1)%b(:) )
  if ( i==2) then
     deallocate (t(1)%b)
     deallocate (t(1)%a)
     deallocate (t)
  end if
end subroutine mah

subroutine mah0 (c)
  !
  integer, intent(OUT) :: c
  type mix_type
     real(8), allocatable :: a(:)
     integer :: n=1023
  end type mix_type
  type(mix_type) :: t
  !
  allocate(t%a(1))
  t%a=3.1415926
  c = t%n
  deallocate(t%a)
  !
end subroutine mah0
!
subroutine mah1 (c)
  !
  integer, intent(OUT) :: c
  type mix_type
     real(8), allocatable :: a(:)
     integer :: n=1023
  end type mix_type
  type(mix_type), save :: t
  !
  allocate(t%a(1))
  t%a=3.1415926
  c = t%n
  deallocate(t%a)
  !
end subroutine mah1