ArrayUtil's boundCheck relies on nonstandard behavior, leads to unit test failure in gcc version >=7
Created by: gridley
To quote 5.3.8.3.3 of the fortran 2003 standard,
The extent of a dimension of an assumed-shape array dummy argument is the extent of the corresponding dimension of its effective argument. If the lower bound value is d and the extent of the corresponding dimension of its effective argument is, then the value of the upper bound is s +d−1. If lower-bound appears it specifies the lower bound; otherwise the lower bound is 1.
It seems boundCheck relies on nonstandard behavior in gcc 4.x that does not adhere to the above's final sentence. I think that gcc 4.x's behavior is indeed more convenient, but unfortunately nonstandard. This simple program summarizes the issue:
program asdf
use iso_fortran_env
implicit none
real(real64), dimension(-5:10) :: arr
print *, 'lbound = ', lbound(arr)
print *, 'ubound = ', ubound(arr)
call boundprinter(arr)
contains
subroutine boundprinter(x)
class(*), intent(in), dimension(:) :: x
print *, 'lbound = ', lbound(x)
print *, 'ubound = ', ubound(x)
endsubroutine boundprinter
endprogram asdf
gridley@necluster ~ $ gfortran asdf.f90
gridley@necluster ~ $ ./a.out
lbound = -5
ubound = 10
lbound = 1
ubound = 16
gridley@necluster ~ $ module load gcc/4.9.3
gridley@necluster ~ $ gfortran --version
GNU Fortran (GCC) 4.9.3
Copyright (C) 2015 Free Software Foundation, Inc.
GNU Fortran comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of GNU Fortran
under the terms of the GNU General Public License.
For more information about these matters, see the file named COPYING
gridley@necluster ~ $ gfortran asdf.f90
gridley@necluster ~ $ ./a.out
lbound = -5
ubound = 10
lbound = -5
ubound = 10
gridley@necluster ~ $
So, it seems that Futility relies on the non-standard compiler feature of gcc 4.x having the lower bound of an assumed shape array not be one but instead be the true lower bound. I'm unsure why they'd prefer the lower bounds of assumed shape arrays not just be what they actually are, but regardless, the code as it stands doesn't conform to the standard in that regard. This causes the ArrayUtils unit test to fail on gcc 8.1.0, and I believe related issues may cause MPACT to segfault on this version of gcc.
It seems that the only alternative would be explicity passing lower bounds to checkBound in ArrayUtils. What are your alls' opinions on this?