* spurious out-of-bounds warning message
[not found] <919875339.3066299.1689174303551.ref@mail.yahoo.com>
@ 2023-07-12 15:05 ` Vivek Rao
2023-07-13 11:53 ` Arjen Markus
0 siblings, 1 reply; 2+ messages in thread
From: Vivek Rao @ 2023-07-12 15:05 UTC (permalink / raw)
To: fortran
For the code
program main
implicit none
integer, parameter :: n = 10
real :: x(n), dx(n)
integer :: i
call random_number(x)
do i=1,n
if (i > 1) then
dx(i) = x(i) - x(i-1)
else
dx(i) = 0.0
end if
end do
print*,dx
end program main
gfortran -Wextra says for GNU Fortran (GCC) 13.0.0 20221218
xspur.f90:9:23:
7 | do i=1,n
| 2
8 | if (i > 1) then
9 | dx(i) = x(i) - x(i-1)
| 1
Warning: Array reference at (1) out of bounds (0 < 1) in loop beginning at (2) [-Wdo-subscript]
but the code is fine because of the if guard. Ideally such spurious messages would be suppressed, but I don't know if this is too hard.
Vivek Rao
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: spurious out-of-bounds warning message
2023-07-12 15:05 ` spurious out-of-bounds warning message Vivek Rao
@ 2023-07-13 11:53 ` Arjen Markus
0 siblings, 0 replies; 2+ messages in thread
From: Arjen Markus @ 2023-07-13 11:53 UTC (permalink / raw)
To: Vivek Rao; +Cc: fortran
[-- Attachment #1: Type: text/plain, Size: 935 bytes --]
I would say it is indeed very hard to capture all false positves.
Regards,
Arjen
Op wo 12 jul 2023 om 17:05 schreef Vivek Rao via Fortran <
fortran@gcc.gnu.org>:
> For the code
>
> program main
> implicit none
> integer, parameter :: n = 10
> real :: x(n), dx(n)
> integer :: i
> call random_number(x)
> do i=1,n
> if (i > 1) then
> dx(i) = x(i) - x(i-1)
> else
> dx(i) = 0.0
> end if
> end do
> print*,dx
> end program main
>
> gfortran -Wextra says for GNU Fortran (GCC) 13.0.0 20221218
>
> xspur.f90:9:23:
>
>
> 7 | do i=1,n
> | 2
> 8 | if (i > 1) then
> 9 | dx(i) = x(i) - x(i-1)
> | 1
> Warning: Array reference at (1) out of bounds (0 < 1) in loop beginning at
> (2) [-Wdo-subscript]
>
> but the code is fine because of the if guard. Ideally such spurious
> messages would be suppressed, but I don't know if this is too hard.
>
> Vivek Rao
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-07-13 11:53 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <919875339.3066299.1689174303551.ref@mail.yahoo.com>
2023-07-12 15:05 ` spurious out-of-bounds warning message Vivek Rao
2023-07-13 11:53 ` Arjen Markus
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).