(The code reflecting the issue is available at GitHub. See also discussions at Fortran Discourse and Flang issue #1200 at GitHub)
Below is a piece of code involving implied do and array constructor. Gfortran, Intel ifort and ifx, NAG nagfor, Absoft af95, and Oracle sunf95 can all handle it, but nvfortran 21.11 encounters errors, which will be detailed in the sequel.
! test.f90 (available at https://github.com/zaikunzhang/test_compiler)
module test_implied_do_mod
implicit none
private
public :: test_implied_do
contains
subroutine test_implied_do()
implicit none
integer :: i
integer :: nfilt
integer, parameter :: maxfilt = 2
logical :: better(maxfilt)
real :: cfilt(maxfilt)
real :: cstrv
real :: f
real :: ffilt(maxfilt)
ffilt = [2.0, 3.0]
cfilt = [3.0, 2.0]
f = 1.0
cstrv = 4.0
nfilt = maxfilt
better(1:nfilt) = [(isbetter([ffilt(i), cfilt(i)], [f, cstrv]), i=1, nfilt)]
if (.not. any(better(1:nfilt))) then
print *, 'Right'
else
print *, 'Wrong'
stop 1
end if
end subroutine test_implied_do
function isbetter(fc1, fc2) result(is_better)
implicit none
real, intent(in) :: fc1(:)
real, intent(in) :: fc2(:)
logical :: is_better
write (*, *) fc1, fc2
is_better = all(fc1 < fc2)
end function isbetter
end module test_implied_do_mod
program test
use, non_intrinsic :: test_implied_do_mod, only : test_implied_do
implicit none
print *, 'Test: Implied do.'
call test_implied_do()
print *, 'Succeed: Implied do.'
end program test
nvfortran 21.11 encounters the following errors.
When invoked without any options
$ nvfortran test.f90
$ ./a.out
Test: Implied do.
0.000000 3.000000 1.000000 4.000000
0.000000 3.000000 1.000000 4.000000
Wrong
1
When invoked with -Mbounds:
$ nvfortran -Mbounds test.f90
$ ./a.out
Test: Implied do.
0: Subscript out of range for array ffilt (testsuite/test_implied_do.f90: 25)
subscript=0, lower bound=1, upper bound=2, dimension=1