aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/class_array_14.f90
blob: ad227a9074ceabeb6cbeca959321fb4d6763cdfa (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
! { dg-do run }
!
! PR fortran/54618
!
! Check whether default initialization works with INTENT(OUT)
! and ALLOCATABLE and no segfault occurs with OPTIONAL.
!

subroutine test1()
  type typ1
    integer :: i = 6
  end type typ1

  type(typ1) :: x

  x%i = 77
  call f(x)
  if (x%i /= 6) call abort ()
  call f()
contains
  subroutine f(y1)
    class(typ1), intent(out), optional :: y1
  end subroutine f
end subroutine test1

subroutine test2()
  type mytype
  end type mytype
  type, extends(mytype):: mytype2
  end type mytype2

  class(mytype), allocatable :: x,y
  allocate (mytype2 :: x)
  call g(x)
  if (allocated (x) .or. .not. same_type_as (x,y)) call abort()

  allocate (mytype2 :: x)
  call h(x)
  if (allocated (x) .or. .not. same_type_as (x,y)) call abort()

  call h()
contains
  subroutine g(y2)
    class(mytype), intent(out), allocatable :: y2
  end subroutine g
  subroutine h(y3)
    class(mytype), optional, intent(out), allocatable :: y3
  end subroutine h
end subroutine test2

call test1()
call test2()
end