Flag to warning about shape/alignment-change of explicit shape arrays arguments
Thomas Koenig
tkoenig@netcologne.de
Thu Jun 6 17:04:00 GMT 2019
Hi Jonatan,
> If you could write bb(3,3,na) and know that unless the actual argument is exactly of shape (3,3,na) the compiler will complain, that would give very clear and safe code.
I have worked on some of the warnings, and what you
propose is somewhere between extremely hard and
impossible to do if na is anything other than
a constant. And I have also some experience with
bug reports about false positives when something like
that is implemented less than perfectly and put it
into -Wextra.
If you really need this particular example, you can always do
type bb_t
real :: a(3,3)
end bb_t
and then declare an array of type bb_t with what size you need.
Access to that type will not be any less efficient than a
normal array access.
What I would sometimes like in the language is some sort of
assert statement, so a user could write
subroutine foo(a,b)
real, dimension(:,:), intent(inout) :: a, b
assert(size(a,1) == size(b,2))
The code could check for that condition statically
(where possible), use the information when not debugging
and thrown an error at run-time when debugging.
Of course,
if (size(a,1) == size(b,2)) stop "Ooops!"
has half of that particular effect, but the compile-time
part is missing (it is perfectly legal to execute a stop
statement).
Regards
Thomas
More information about the Fortran
mailing list