summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/allocate_alloc_opt_6.f90
blob: d470b424a1ce41bfe9f66f850d12d79e4bef52a4 (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
! { dg-do run }
program a

  implicit none

  type :: mytype
    real ::  r
    integer :: i
  end type mytype
  
  integer n
  integer, allocatable :: i(:)
  real z
  real, allocatable :: x(:)
  type(mytype), pointer :: t

  n = 42
  z = 99.

  allocate(i(4), source=n)
  if (any(i /= 42)) call abort

  allocate(x(4), source=z)
  if (any(x /= 99.)) call abort

  allocate(t, source=mytype(1.0,2))
  if (t%r /= 1. .or. t%i /= 2) call abort

  deallocate(i)
  allocate(i(3), source=(/1, 2, 3/))
  if (i(1) /= 1 .or. i(2) /= 2 .or. i(3) /= 3) call abort

  call sub1(i)

end program a

subroutine sub1(j)
   integer, intent(in) :: j(*)
   integer, allocatable :: k(:)
   allocate(k(2), source=j(1:2))
   if (k(1) /= 1 .or. k(2) /= 2) call abort
end subroutine sub1