| 1 |
! { dg-do compile } |
| 2 |
! |
| 3 |
! Contributed by Neil Carlson <[email protected]> |
| 4 |
! |
| 5 |
module mod |
| 6 |
type :: foo |
| 7 |
real, pointer :: var |
| 8 |
contains |
| 9 |
procedure :: var_ptr |
| 10 |
end type |
| 11 |
contains |
| 12 |
function var_ptr(this) result(ref) |
| 13 |
class(foo) :: this |
| 14 |
real, pointer :: ref |
| 15 |
ref => this%var |
| 16 |
end function |
| 17 |
end module |
| 18 |
program main |
| 19 |
use mod |
| 20 |
type(foo) :: x |
| 21 |
allocate (x%var, source = 2.0) |
| 22 |
associate (var => x%var_ptr()) |
| 23 |
var = 1.0 |
| 24 |
end associate |
| 25 |
if (x%var .ne. 1.0) stop 1 |
| 26 |
x%var_ptr() = 2.0 |
| 27 |
if (x%var .ne. 2.0) stop 2 |
| 28 |
deallocate (x%var) |
| 29 |
end program |