aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.9/gcc/testsuite/gfortran.dg/ret_pointer_2.f90
blob: 939411b7bc22c2dcae617e2e499d0d1a494c1ff3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
! { dg-do run }
! PR 25806: Functions returning pointers to arrays
program a 
    integer, target :: storage(5)
    integer :: s(3)


    print *, x(3)  ! { dg-output " *1  *2  *3" }

    if (ssum(x(3)) /= 6) call abort()

    s = 0
    s = x(3)
    if (any(s /= (/1, 2, 3/))) call abort()

contains

    function x(n) result(t)
        integer, intent(in) :: n
        integer, pointer :: t(:)
        integer :: i

        t => storage(1:n)
        t = (/ (i, i = 1, n) /)

    end function x


    integer function ssum(a)
        integer, intent(in) :: a(:)

        ssum = sum(a)
        
    end function ssum

end program a