| 1 |
! { dg-do run } |
| 2 |
! PR 25806: Functions returning pointers to arrays |
| 3 |
program a |
| 4 |
integer, target :: storage(5) |
| 5 |
integer :: s(3) |
| 6 |
|
| 7 |
|
| 8 |
print *, x(3) ! { dg-output " *1 *2 *3" } |
| 9 |
|
| 10 |
if (ssum(x(3)) /= 6) STOP 1 |
| 11 |
|
| 12 |
s = 0 |
| 13 |
s = x(3) |
| 14 |
if (any(s /= (/1, 2, 3/))) STOP 2 |
| 15 |
|
| 16 |
contains |
| 17 |
|
| 18 |
function x(n) result(t) |
| 19 |
integer, intent(in) :: n |
| 20 |
integer, pointer :: t(:) |
| 21 |
integer :: i |
| 22 |
|
| 23 |
t => storage(1:n) |
| 24 |
t = (/ (i, i = 1, n) /) |
| 25 |
|
| 26 |
end function x |
| 27 |
|
| 28 |
|
| 29 |
integer function ssum(a) |
| 30 |
integer, intent(in) :: a(:) |
| 31 |
|
| 32 |
ssum = sum(a) |
| 33 |
|
| 34 |
end function ssum |
| 35 |
|
| 36 |
end program a |
| 37 |
|
| 38 |
|