| 1 |
! { dg-do run } |
| 2 |
! { dg-options "-Wexternal-argument-mismatch" } |
| 3 |
! Originally proc_ptr_52.f90, this gave an error with the warning above. |
| 4 |
|
| 5 |
module cs |
| 6 |
|
| 7 |
implicit none |
| 8 |
|
| 9 |
integer, target :: integer_target |
| 10 |
|
| 11 |
abstract interface |
| 12 |
function classStar_map_ifc(x) result(y) |
| 13 |
class(*), pointer :: y |
| 14 |
class(*), target, intent(in) :: x |
| 15 |
end function classStar_map_ifc |
| 16 |
end interface |
| 17 |
|
| 18 |
contains |
| 19 |
|
| 20 |
function fun(x) result(y) |
| 21 |
class(*), pointer :: y |
| 22 |
class(*), target, intent(in) :: x |
| 23 |
select type (x) |
| 24 |
type is (integer) |
| 25 |
integer_target = x ! Deals with dangling target. |
| 26 |
y => integer_target |
| 27 |
class default |
| 28 |
y => null() |
| 29 |
end select |
| 30 |
end function fun |
| 31 |
|
| 32 |
function apply(fap, x) result(y) |
| 33 |
procedure(classStar_map_ifc) :: fap |
| 34 |
integer, intent(in) :: x |
| 35 |
integer :: y |
| 36 |
class(*), pointer :: p |
| 37 |
y = 0 ! Get rid of 'y' undefined warning |
| 38 |
p => fap (x) |
| 39 |
select type (p) |
| 40 |
type is (integer) |
| 41 |
y = p |
| 42 |
end select |
| 43 |
end function apply |
| 44 |
|
| 45 |
function selector() result(fsel) |
| 46 |
procedure(classStar_map_ifc), pointer :: fsel |
| 47 |
fsel => fun |
| 48 |
end function selector |
| 49 |
|
| 50 |
end module cs |
| 51 |
|
| 52 |
|
| 53 |
program classStar_map |
| 54 |
|
| 55 |
use cs |
| 56 |
implicit none |
| 57 |
|
| 58 |
integer :: x, y |
| 59 |
procedure(classStar_map_ifc), pointer :: fm |
| 60 |
|
| 61 |
x = 123654 |
| 62 |
fm => selector () ! Fixed by second chunk in patch |
| 63 |
y = apply (fm, x) ! Fixed by first chunk in patch |
| 64 |
if (x .ne. y) stop 1 |
| 65 |
|
| 66 |
x = 2 * x |
| 67 |
y = apply (fun, x) ! PR93925; fixed as above |
| 68 |
if (x .ne. y) stop 2 |
| 69 |
|
| 70 |
end program classStar_map |