| 1 |
! { dg-do run } |
| 2 |
! |
| 3 |
! Tests pointer function selectors in ASSOCIATE. |
| 4 |
! |
| 5 |
! Contributed by Harald Anlauf <[email protected]> in |
| 6 |
! https://gcc.gnu.org/pipermail/fortran/2024-March/060294.html |
| 7 |
program paul |
| 8 |
implicit none |
| 9 |
type t |
| 10 |
integer :: i |
| 11 |
end type t |
| 12 |
type(t), pointer :: p(:) |
| 13 |
integer :: j |
| 14 |
allocate (p(-3:3)) |
| 15 |
p% i = [(j,j=-3,3)] |
| 16 |
|
| 17 |
associate (q => p) |
| 18 |
print *, lbound (q), ubound (q) ! Should print -3 3 (OK) |
| 19 |
print *, q% i |
| 20 |
end associate |
| 21 |
|
| 22 |
associate (q => set_ptr()) |
| 23 |
print *, lbound (q), ubound (q) ! Should print -3 3 (OK) |
| 24 |
print *, q(:)% i ! <<< ... has no IMPLICIT type |
| 25 |
end associate |
| 26 |
|
| 27 |
associate (q => (p)) |
| 28 |
print *, lbound (q), ubound (q) ! Should print 1 7 (OK) |
| 29 |
print *, q% i |
| 30 |
end associate |
| 31 |
|
| 32 |
associate (q => (set_ptr())) |
| 33 |
print *, lbound (q), ubound (q) ! Should print 1 7 (OK) |
| 34 |
print *, q(:)% i ! <<< ... has no IMPLICIT type |
| 35 |
end associate |
| 36 |
contains |
| 37 |
function set_ptr () result (res) |
| 38 |
type(t), pointer :: res(:) |
| 39 |
res => p |
| 40 |
end function set_ptr |
| 41 |
end |