2 ! Test the fix for comment 1 in PR113363, which failed as in comments below.
3 ! Contributed by Harald Anlauf <anlauf@gcc.gnu.org>
6 class(*), allocatable
:: x(:), y
7 character(*), parameter :: arr(2) = ["hello ","bye "], &
8 sca
= "Have a nice day"
11 ! Bug was detected in polymorphic array function results
12 allocate(x
, source
= foo ())
13 call check1 (x
, arr
) ! Wrong output "6 hello e"
16 call check1 (x
, arr
) ! Wrong output "0 "
17 associate (var
=> foo ()) ! OK after r14-9489-g3fd46d859cda10
18 call check1 (var
, arr
) ! Now OK - outputs: "6 hello bye "
21 ! Check scalar function results ! All OK
22 allocate (y
, source
= bar())
28 associate (var
=> bar ())
29 call check2 (var
, sca
)
32 ! Finally variable expressions...
33 allocate (y
, source
= x(1)) ! Gave zero length here
34 call check2 (y
, "hello")
35 y
= x(2) ! Segfaulted here
36 call check2 (y
, "bye ")
37 associate (var
=> x(2)) ! Gave zero length here
38 call check2 (var
, "bye ")
41 ! ...and constant expressions ! All OK
43 allocate (y
, source
= "abcde")
44 call check2 (y
, "abcde")
47 call check2 (y
, "hijklmnopq")
48 associate (var
=> "mnopq")
49 call check2 (var
, "mnopq")
55 function foo() result(res
)
56 class(*), allocatable
:: res(:)
60 function bar() result(res
)
61 class(*), allocatable
:: res
65 subroutine check1 (x
, carg
)
66 class(*), intent(in
) :: x(:)
67 character(*) :: carg(:)
69 type is (character(*))
70 if (any (x
.ne
. carg
)) stop 1
76 subroutine check2 (x
, carg
)
77 class(*), intent(in
) :: x
80 type is (character(*))
81 if (x
.ne
. carg
) stop 3