OSDN Git Service

2010-07-29 Tobias Burnus <burnus@net-b.de>
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gfortran.dg / alloc_comp_default_init_1.f90
1 ! { dg-do run }
2 ! Checks the fixes for PR34681 and PR34704, in which various mixtures\r
3 ! of default initializer and allocatable array were not being handled\r
4 ! correctly for derived types with allocatable components.
5 !
6 ! Contributed by Paolo Giannozzi <p.giannozzi@fisica.uniud.it>
7 !
8 program boh
9   integer :: c1, c2, c3, c4, c5\r
10   !\r
11   call mah (0, c1) ! These calls deal with PR34681\r
12   call mah (1, c2)\r
13   call mah (2, c3)\r
14   !
15   if (c1 /= c2) call abort
16   if (c1 /= c3) call abort\r
17   !\r
18   call mah0 (c4) ! These calls deal with PR34704\r
19   call mah1 (c5)\r
20   !
21   if (c4 /= c5) call abort
22   !\r
23 end program boh\r
24 !\r
25 subroutine mah (i, c)\r
26   !\r
27   integer, intent(in) :: i\r
28   integer, intent(OUT) :: c\r
29   !\r
30   type mix_type\r
31      real(8), allocatable :: a(:)\r
32      complex(8), allocatable :: b(:)\r
33   end type mix_type\r
34   type(mix_type), allocatable, save :: t(:)\r
35   integer :: j, n=1024\r
36   !\r
37   if (i==0) then\r
38      allocate (t(1))\r
39      allocate (t(1)%a(n))\r
40      allocate (t(1)%b(n))\r
41      do j=1,n\r
42         t(1)%a(j) = j\r
43         t(1)%b(j) = n-j\r
44      end do\r
45   end if\r
46   c = sum( t(1)%a(:) ) + sum( t(1)%b(:) )\r
47   if ( i==2) then\r
48      deallocate (t(1)%b)\r
49      deallocate (t(1)%a)\r
50      deallocate (t)\r
51   end if\r
52 end subroutine mah
53
54 subroutine mah0 (c)\r
55   !\r
56   integer, intent(OUT) :: c\r
57   type mix_type\r
58      real(8), allocatable :: a(:)\r
59      integer :: n=1023\r
60   end type mix_type\r
61   type(mix_type) :: t\r
62   !\r
63   allocate(t%a(1))\r
64   t%a=3.1415926\r
65   c = t%n\r
66   deallocate(t%a)\r
67   !\r
68 end subroutine mah0\r
69 !\r
70 subroutine mah1 (c)\r
71   !\r
72   integer, intent(OUT) :: c\r
73   type mix_type\r
74      real(8), allocatable :: a(:)\r
75      integer :: n=1023\r
76   end type mix_type\r
77   type(mix_type), save :: t\r
78   !\r
79   allocate(t%a(1))\r
80   t%a=3.1415926\r
81   c = t%n\r
82   deallocate(t%a)\r
83   !\r
84 end subroutine mah1\r