re PR fortran/83548 (Compilation Error using logical function in parameter)
[official-gcc.git] / gcc / testsuite / gfortran.dg / alloc_comp_class_4.f03
blob28b7e631a874eca6b8eb78670708f3a93feb6d96
1 ! { dg-do run }
2 ! { dg-options "-Wreturn-type" }
4 ! Check that pr58586 is fixed now.
5 ! Based on a contribution by Vladimir Fuka
6 ! Contibuted by Andre Vehreschild
8 module test_pr58586_mod
9   implicit none
11   type :: a
12   end type
14   type :: c
15      type(a), allocatable :: a
16   end type
18   type :: d
19   contains
20      procedure :: init => d_init
21   end type
23   type, extends(d) :: e
24   contains
25      procedure :: init => e_init
26   end type
28   type :: b
29      integer, allocatable :: a
30   end type
32   type t
33     integer :: i = 5
34   end type
36 contains
38   subroutine add (d)
39     type(b), value :: d
40   end subroutine
42   subroutine add_c (d)
43     type(c), value :: d
44   end subroutine
46   subroutine add_class_c (d)
47     class(c), value :: d
48   end subroutine
50   subroutine add_t (d)
51     type(t), value :: d
52   end subroutine
54   type(c) function c_init() ! { dg-warning "not set" }
55   end function
57   class(c) function c_init2() ! { dg-warning "not set" }
58     allocatable :: c_init2
59   end function
61   type(c) function d_init(this) ! { dg-warning "not set" }
62     class(d) :: this
63   end function
65   type(c) function e_init(this)
66     class(e) :: this
67     allocate (e_init%a)
68   end function
70   type(t) function t_init() ! { dg-warning "not set" }
71     allocatable :: t_init
72   end function
74   type(t) function static_t_init() ! { dg-warning "not set" }
75   end function
76 end module test_pr58586_mod
78 program test_pr58586
79   use test_pr58586_mod
81   class(d), allocatable :: od
82   class(e), allocatable :: oe
83   type(t), allocatable :: temp
85   ! These two are merely to check, if compilation works
86   call add(b())
87   call add(b(null()))
89   ! This needs to execute, to see whether the segfault at runtime is resolved
90   call add_c(c_init())
91   call add_class_c(c_init2())
93   call add_t(static_t_init())
94   ! temp = t_init() ! <-- This derefs a null-pointer currently
95   ! Filed as pr66775
96   if (allocated (temp)) call abort()
98   allocate(od)
99   call add_c(od%init())
100   deallocate(od)
101   allocate(oe)
102   call add_c(oe%init())
103   deallocate(oe)
104 end program