lto: Remove random_seed from section name.
[official-gcc.git] / gcc / testsuite / gfortran.dg / assumed_rank_21.f90
blobef5edbfb6ed1bda93beb286a21898e98582af343
1 ! { dg-do run }
3 ! Test the fix for PR98342.
5 ! Contributed by Martin Stein <mscfd@gmx.net>
7 module mod
8 implicit none
9 private
10 public get_tuple, sel_rank1, sel_rank2, sel_rank3
12 type, public :: tuple
13 integer, dimension(:), allocatable :: t
14 end type tuple
16 contains
18 function sel_rank1(x) result(s)
19 character(len=:), allocatable :: s
20 type(tuple), dimension(..), intent(in) :: x
21 select rank (x)
22 rank (0)
23 s = '10'
24 rank (1)
25 s = '11'
26 rank default
27 s = '?'
28 end select
29 end function sel_rank1
31 function sel_rank2(x) result(s)
32 character(len=:), allocatable :: s
33 class(tuple), dimension(..), intent(in) :: x
34 select rank (x)
35 rank (0)
36 s = '20'
37 rank (1)
38 s = '21'
39 rank default
40 s = '?'
41 end select
42 end function sel_rank2
44 function sel_rank3(x) result(s)
45 character(len=:), allocatable :: s
46 class(*), dimension(..), intent(in) :: x
47 select rank (x)
48 rank (0)
49 s = '30'
50 rank (1)
51 s = '31'
52 rank default
53 s = '?'
54 end select
55 end function sel_rank3
57 function get_tuple(t) result(a)
58 type(tuple) :: a
59 integer, dimension(:), intent(in) :: t
60 allocate(a%t, source=t)
61 end function get_tuple
63 end module mod
66 program alloc_rank
67 use mod
68 implicit none
70 integer, dimension(1:3) :: x
71 character(len=:), allocatable :: output
72 type(tuple) :: z
74 x = [1,2,3]
75 z = get_tuple (x)
76 ! Derived type formal arg
77 output = sel_rank1(get_tuple (x)) ! runtime: Error in `./alloc_rank.x':
78 if (output .ne. '10') stop 1
79 output = sel_rank1([z]) ! This worked OK
80 if (output .ne. '11') stop 2
82 ! Class formal arg
83 output = sel_rank2(get_tuple (x)) ! runtime: Error in `./alloc_rank.x':
84 if (output .ne. '20') stop 3
85 output = sel_rank2([z]) ! This worked OK
86 if (output .ne. '21') stop 4
88 ! Unlimited polymorphic formal arg
89 output = sel_rank3(get_tuple (x)) ! runtime: Error in `./alloc_rank.x':
90 if (output .ne. '30') stop 5
91 output = sel_rank3([z]) ! runtime: segmentation fault
92 if (output .ne. '31') stop 6
94 deallocate (output)
95 deallocate (z%t)
96 end program alloc_rank