1! { dg-do run }
2!
3! Test the fix for PR82923, in which an ICE occurred because the
4! character length from 'getchars' scope was being used in the
5! automatic allocation of 'mine'.
6!
7! Contributed by "Werner Blokbuster"  <werner.blokbuster@gmail.com>
8!
9module m
10    implicit none
11contains
12    function getchars(my_len,my_size)
13        integer, intent(in) :: my_len, my_size
14        character(my_len) :: getchars(my_size)
15            getchars = 'A-'
16    end function getchars
17
18    function getchars2(my_len)
19        integer, intent(in) :: my_len
20        character(my_len) :: getchars2
21            getchars2 = 'B--'
22    end function getchars2
23end module m
24
25program testca
26    use m, only: getchars, getchars2
27    implicit none
28    character(:), allocatable :: mine(:)
29    character(:), allocatable :: mine2
30    integer :: i
31
32    ! ICE occured at this line:
33    mine = getchars(2,4)
34    if (any (mine .ne. [('A-', i = 1, 4)])) stop 1
35
36    ! The scalar version was fine and this will keep it so:
37    mine2 = getchars2(3)
38    if (mine2 .ne. 'B--') stop 2
39end program testca
40