| 1 |
! { dg-do run } |
| 2 |
! PR fortran/89384 - this used to give a wrong results |
| 3 |
! with contiguous. |
| 4 |
! The subroutine substr is a test to check a problem found while |
| 5 |
! debugging PR90355. |
| 6 |
! |
| 7 |
! Test case by Reinhold Bader. |
| 8 |
! |
| 9 |
module mod_ctg |
| 10 |
implicit none |
| 11 |
|
| 12 |
contains |
| 13 |
|
| 14 |
subroutine ctg(x) BIND(C) |
| 15 |
real, contiguous :: x(:) |
| 16 |
if (any(abs(x - [2.,4.,6.]) > 1.e-6)) stop 1 |
| 17 |
x = [2.,4.,6.]*10.0 |
| 18 |
end subroutine |
| 19 |
|
| 20 |
subroutine substr(str) BIND(C) |
| 21 |
character(*) :: str(:) |
| 22 |
if (str(1) .ne. "bcd") stop 2 |
| 23 |
if (str(2) .ne. "ghi") stop 3 |
| 24 |
str = ['uvw','xyz'] |
| 25 |
end subroutine |
| 26 |
|
| 27 |
subroutine substr4(str4) BIND(C) |
| 28 |
character(*, kind=4) :: str4(:) |
| 29 |
print *, str4(1) |
| 30 |
print *, str4(2) |
| 31 |
if (str4(1) .ne. 4_"bcd") stop 4 |
| 32 |
if (str4(2) .ne. 4_"ghi") stop 5 |
| 33 |
str4 = [4_'uvw', 4_'xyz'] |
| 34 |
end subroutine |
| 35 |
|
| 36 |
end module |
| 37 |
|
| 38 |
program p |
| 39 |
use mod_ctg |
| 40 |
implicit none |
| 41 |
real :: x(6) |
| 42 |
character(5) :: str(2) = ['abcde', 'fghij'] |
| 43 |
character(5, kind=4) :: str4(2) = [4_'abcde', 4_'fghij'] |
| 44 |
integer :: i |
| 45 |
|
| 46 |
x = [ (real(i), i=1, size(x)) ] |
| 47 |
call ctg(x(2::2)) |
| 48 |
if (any (abs (x - [1.,20.,3.,40.,5.,60.]) > 1.e-6)) stop 3 |
| 49 |
|
| 50 |
!call substr(str(:)(2:4)) |
| 51 |
!if (any (str .ne. ['auvwe','fxyzj'])) stop 4 |
| 52 |
|
| 53 |
call substr4(str4(:)(2:4)) |
| 54 |
if (any (str4 .ne. [4_'auvwe', 4_'fxyzj'])) stop 4 |
| 55 |
end program |