| 1 |
! { dg-do run } |
| 2 |
! The compiler_options() function is dependent on the |
| 3 |
! command line options and thus incompatible with -fcompare-debug. |
| 4 |
! { dg-skip-if "-fcompare-debug incompatible test" { *-*-* } { "-fcompare-debug" } { "" } } */ |
| 5 |
! |
| 6 |
! Test the fix for PR92785, where the array passed to 'write scalar' was not |
| 7 |
! normalised to LBOUND = 1. |
| 8 |
! |
| 9 |
! Contributed by <[email protected]> |
| 10 |
! |
| 11 |
program tst |
| 12 |
use iso_fortran_env, only : compiler_version, compiler_options |
| 13 |
implicit none |
| 14 |
integer :: i |
| 15 |
integer :: ibad=0 |
| 16 |
integer :: iarr(10) = [(i*10, i = 1,size (iarr))] |
| 17 |
character(len=:), allocatable :: line |
| 18 |
character(len=*), parameter :: expected = '10 20 30 40 50 60 70 80 90 100' |
| 19 |
character(len=*), parameter :: expected_minus = '-10 -20 -30 -40 -50 -60 -70 -80 -90 -100' |
| 20 |
print '(4a)', & |
| 21 |
'This file was compiled by ', compiler_version(), & |
| 22 |
' using the options ', compiler_options() |
| 23 |
call write_row ('iarr ', iarr) ! pass in the array, OK |
| 24 |
call write_row ('iarr+0 ', iarr+0) ! pass in an expression, NOT OK |
| 25 |
call write_row ('-iarr ', -iarr) ! pass in an expression, NOT OK |
| 26 |
call write_row ('iarr(::1) ', iarr(::1)) ! pass in the array, OK |
| 27 |
call write_row ('[iarr(::1)] ', [iarr(::1)]) ! pass in compound constructor, NOT OK |
| 28 |
call write_row ('[(i*10,i=1,size(iarr))]', [(i*10,i=1,size(iarr))]) ! pass in constructor, OK |
| 29 |
call write_row ('10*[(i,i=1,size(iarr))]', 10*[(i,i=1,size(iarr))]) ! pass in constructor, OK |
| 30 |
if (ibad .gt. 0) stop 1 |
| 31 |
contains |
| 32 |
subroutine write_scalar (g1) |
| 33 |
class(*) :: g1 |
| 34 |
character(len = 20) :: word |
| 35 |
select type(g1) |
| 36 |
type is (integer) |
| 37 |
write (word, '(i0)') g1 |
| 38 |
line = line // trim( word) // ' ' |
| 39 |
end select |
| 40 |
end subroutine write_scalar |
| 41 |
subroutine write_row (string,array) |
| 42 |
character(len = *) :: string |
| 43 |
class(*) :: array(:) |
| 44 |
integer :: i |
| 45 |
line = '' |
| 46 |
do i = 1, size (array) |
| 47 |
call write_scalar (array(i)) |
| 48 |
enddo |
| 49 |
if (expected .eq. line) then |
| 50 |
write (*, *) string, ':GOOD' |
| 51 |
else if (expected_minus .eq. line) then |
| 52 |
write (*, *) string, ':GOOD' |
| 53 |
else |
| 54 |
write (*, *) string, ':BAD. EXPECTED [', expected, '] got [', trim (line),']' |
| 55 |
ibad = ibad + 1 |
| 56 |
endif |
| 57 |
end subroutine write_row |
| 58 |
end program tst |