| 1 |
! { dg-do run } |
| 2 |
! PR fortran/114827 - issues with class(*) assignment found by valgrind |
| 3 |
! |
| 4 |
! Contributed by Neil Carlson <[email protected]> |
| 5 |
|
| 6 |
program main |
| 7 |
implicit none |
| 8 |
call run |
| 9 |
call run1 |
| 10 |
call run2 |
| 11 |
contains |
| 12 |
! Scalar tests |
| 13 |
subroutine run () |
| 14 |
character(*), parameter :: c = 'fubarfubarfubarfubarfubarfu' |
| 15 |
character(*,kind=4), parameter :: d = 4_"abcdef" |
| 16 |
complex, parameter :: z = (1.,2.) |
| 17 |
class(*), allocatable :: y |
| 18 |
|
| 19 |
call foo (c, y) |
| 20 |
select type (y) |
| 21 |
type is (character(*)) |
| 22 |
! print *, y(5:6) ! ICE (-> pr114874) |
| 23 |
if (y /= c) stop 1 |
| 24 |
class default |
| 25 |
stop 2 |
| 26 |
end select |
| 27 |
|
| 28 |
call foo (z, y) |
| 29 |
select type (y) |
| 30 |
type is (complex) |
| 31 |
if (y /= z) stop 3 |
| 32 |
class default |
| 33 |
stop 4 |
| 34 |
end select |
| 35 |
|
| 36 |
call foo (d, y) |
| 37 |
select type (y) |
| 38 |
type is (character(*,kind=4)) |
| 39 |
! print *, y ! NAG fails here |
| 40 |
if (y /= d) stop 5 |
| 41 |
class default |
| 42 |
stop 6 |
| 43 |
end select |
| 44 |
end subroutine |
| 45 |
! |
| 46 |
subroutine foo (a, b) |
| 47 |
class(*), intent(in) :: a |
| 48 |
class(*), allocatable :: b |
| 49 |
b = a |
| 50 |
end subroutine |
| 51 |
|
| 52 |
! Rank-1 tests |
| 53 |
subroutine run1 () |
| 54 |
character(*), parameter :: c(*) = ['fubar','snafu'] |
| 55 |
character(*,kind=4), parameter :: d(*) = [4_"abc",4_"def"] |
| 56 |
real, parameter :: r(*) = [1.,2.,3.] |
| 57 |
class(*), allocatable :: y(:) |
| 58 |
|
| 59 |
call foo1 (c, y) |
| 60 |
select type (y) |
| 61 |
type is (character(*)) |
| 62 |
! print *, ">",y(2)(1:3),"< >", c(2)(1:3), "<" |
| 63 |
if (any (y /= c)) stop 11 |
| 64 |
if (y(2)(1:3) /= c(2)(1:3)) stop 12 |
| 65 |
class default |
| 66 |
stop 13 |
| 67 |
end select |
| 68 |
|
| 69 |
call foo1 (r, y) |
| 70 |
select type (y) |
| 71 |
type is (real) |
| 72 |
if (any (y /= r)) stop 14 |
| 73 |
class default |
| 74 |
stop 15 |
| 75 |
end select |
| 76 |
|
| 77 |
call foo1 (d, y) |
| 78 |
select type (y) |
| 79 |
type is (character(*,kind=4)) |
| 80 |
! print *, ">",y(2)(2:3),"< >", d(2)(2:3), "<" |
| 81 |
if (any (y /= d)) stop 16 |
| 82 |
class default |
| 83 |
stop 17 |
| 84 |
end select |
| 85 |
end subroutine |
| 86 |
! |
| 87 |
subroutine foo1 (a, b) |
| 88 |
class(*), intent(in) :: a(:) |
| 89 |
class(*), allocatable :: b(:) |
| 90 |
b = a |
| 91 |
end subroutine |
| 92 |
|
| 93 |
! Rank-2 tests |
| 94 |
subroutine run2 () |
| 95 |
character(7) :: c(2,3) |
| 96 |
complex :: z(3,3) |
| 97 |
integer :: i, j |
| 98 |
class(*), allocatable :: y(:,:) |
| 99 |
|
| 100 |
c = reshape (['fubar11','snafu21',& |
| 101 |
'fubar12','snafu22',& |
| 102 |
'fubar13','snafu23'],shape(c)) |
| 103 |
call foo2 (c, y) |
| 104 |
select type (y) |
| 105 |
type is (character(*)) |
| 106 |
! print *, y(2,1) |
| 107 |
if (y(2,1) /= c(2,1)) stop 21 |
| 108 |
if (any (y /= c)) stop 22 |
| 109 |
class default |
| 110 |
stop 23 |
| 111 |
end select |
| 112 |
|
| 113 |
do j = 1, size (z,2) |
| 114 |
do i = 1, size (z,1) |
| 115 |
z(i,j) = cmplx (i,j) |
| 116 |
end do |
| 117 |
end do |
| 118 |
call foo2 (z, y) |
| 119 |
select type (y) |
| 120 |
type is (complex) |
| 121 |
! print *, y(2,1) |
| 122 |
if (any (y%re /= z%re)) stop 24 |
| 123 |
if (any (y%im /= z%im)) stop 25 |
| 124 |
class default |
| 125 |
stop 26 |
| 126 |
end select |
| 127 |
end subroutine |
| 128 |
! |
| 129 |
subroutine foo2 (a, b) |
| 130 |
class(*), intent(in) :: a(:,:) |
| 131 |
class(*), allocatable :: b(:,:) |
| 132 |
b = a |
| 133 |
end subroutine |
| 134 |
|
| 135 |
end program |