I just stumbled upon some weird behavior in ifort 22.214.171.124 on CentOS 7. I am not entirely sure if this is a bug with the compiler or if it's non-standard Fortran so I wanted to ask here. Below is a MWE that illustrates the issue:
program test implicit none integer, allocatable :: a(:), b1(:), b2(:, :) b1 = [2, 1] b2 = reshape([1, -1, -2, -3, -4, 2, -5, -6, -7, -8], [5, 2]) a = b1(b2(1, :)) write(*, *) shape(a), "|", a end program test
What's important is that the output of this program depends on whether one uses runtime checks (-C) or not. Basically, we use b2(1,
2 | 2 1
However, after enabling runtime checks, the output changes to:
1 | 2
Is there something wrong with the code? I do believe all of this should be valid Fortran (2003).
I would say it is conforming. I can also confirm that the program works with Intel Fortran 2018, with and without -C (or -check:all). I get the same answer. gfortran also accepts it and produces the same output.
This is fixed in the latest compiler release, 2021.2.0. It was made available last week. Please give it a try.
$ GO ifort (IFORT) 2021.2.0 20210228 Copyright (C) 1985-2021 Intel Corporation. All rights reserved. + ifort -C c.f90 + a.out 2 | 2 1 + ifort -C -check noshape c.f90 + a.out 2 | 2 1 + ifort -check shape c.f90 + a.out 2 | 2 1