Debian Codegraph @

gcc/testsuite/gfortran.dg/derived_result_5.f90

raw
1 ! { dg-do run }
2 ! { dg-additional-options "-O2 -Wreturn-type" }
3 !
4 ! PR fortran/85750 - default-initialization and functions returning derived type
5
6 module bar
7 implicit none
8 type ilist
9 integer :: count = 42
10 integer, pointer :: ptr(:) => null()
11 end type ilist
12
13 type jlist
14 real, allocatable :: a(:)
15 integer :: count = 23
16 end type jlist
17
18 contains
19
20 function make_list(i)
21 integer, intent(in) :: i
22 type(ilist), dimension(2) :: make_list
23 make_list(i)%count = i
24 end function make_list
25
26 function make_list_res(i) result(list)
27 integer, intent(in) :: i
28 type(ilist), dimension(2) :: list
29 list(i)%count = i
30 end function make_list_res
31
32 function make_jlist(i)
33 integer, intent(in) :: i
34 type(jlist), dimension(2) :: make_jlist
35 make_jlist(i)%count = i
36 end function make_jlist
37
38 function make_jlist_res(i) result(list)
39 integer, intent(in) :: i
40 type(jlist), dimension(2) :: list
41 list(i)%count = i
42 end function make_jlist_res
43
44 function empty_ilist()
45 type(ilist), dimension(2) :: empty_ilist
46 end function
47
48 function empty_jlist()
49 type(jlist), dimension(2) :: empty_jlist
50 end function
51
52 function empty_ilist_res() result (res)
53 type(ilist), dimension(2) :: res
54 end function
55
56 function empty_jlist_res() result (res)
57 type(jlist), dimension(2) :: res
58 end function
59
60 end module bar
61
62 program foo
63 use bar
64 implicit none
65 type(ilist) :: mylist(2) = ilist(count=-2)
66 type(jlist), allocatable :: yourlist(:)
67
68 mylist = ilist(count=-1)
69 if (any (mylist%count /= [-1,-1])) stop 1
70 mylist = empty_ilist()
71 if (any (mylist%count /= [42,42])) stop 2
72 mylist = ilist(count=-1)
73 mylist = empty_ilist_res()
74 if (any (mylist%count /= [42,42])) stop 3
75
76 allocate(yourlist(1:2))
77 if (any (yourlist%count /= [23,23])) stop 4
78 yourlist = jlist(count=-1)
79 if (any (yourlist%count /= [-1,-1])) stop 5
80 yourlist = empty_jlist()
81 if (any (yourlist%count /= [23,23])) stop 6
82 yourlist = jlist(count=-1)
83 yourlist = empty_jlist_res()
84 if (any (yourlist%count /= [23,23])) stop 7
85
86 mylist = make_list(1)
87 if (any (mylist%count /= [1,42])) stop 11
88 mylist = make_list(2)
89 if (any (mylist%count /= [42,2])) stop 12
90 mylist = (make_list(1))
91 if (any (mylist%count /= [1,42])) stop 13
92 mylist = [make_list(2)]
93 if (any (mylist%count /= [42,2])) stop 14
94
95 mylist = make_list_res(1)
96 if (any (mylist%count /= [1,42])) stop 21
97 mylist = make_list_res(2)
98 if (any (mylist%count /= [42,2])) stop 22
99 mylist = (make_list_res(1))
100 if (any (mylist%count /= [1,42])) stop 23
101 mylist = [make_list_res(2)]
102 if (any (mylist%count /= [42,2])) stop 24
103
104 yourlist = make_jlist(1)
105 if (any (yourlist%count /= [1,23])) stop 31
106 yourlist = make_jlist(2)
107 if (any (yourlist%count /= [23,2])) stop 32
108 yourlist = (make_jlist(1))
109 if (any (yourlist%count /= [1,23])) stop 33
110 yourlist = [make_jlist(2)]
111 if (any (yourlist%count /= [23,2])) stop 34
112
113 yourlist = make_jlist_res(1)
114 if (any (yourlist%count /= [1,23])) stop 41
115 yourlist = make_jlist_res(2)
116 if (any (yourlist%count /= [23,2])) stop 42
117 yourlist = (make_jlist_res(1))
118 if (any (yourlist%count /= [1,23])) stop 43
119 yourlist = [make_jlist_res(2)]
120 if (any (yourlist%count /= [23,2])) stop 44
121
122 deallocate (yourlist)
123 end program foo