Very big ramble about associates

So I left my code unattended for about 2 years. One of the big selling points of Fortran, at least the way I see it, is that the codes should not “age” as fast as some younger ecosystems, such as Python. Meanwhile, jumping from gfortran 12 to 13, my code would not compile anymore, with an associate statement that I would consider correct:

././src/findstar.f90:96:49:

   96 |       associate (ilo => max(xymax(1) - rslice, 1), &
      |                                                 1
Error: Symbol ‘ilo’ at (1) has no IMPLICIT type
<ERROR> Compilation failed for object " src_findstar.f90.o "
<ERROR> stopping due to failed compilation

Moving over to ifort or ifx, both segfault at the second line of this little block:

          associate (calibarea => frame_flat % data(33:n1-32, 33:n2-32))
            frame_flat % data(:,:) = frame_flat % data / average_safe(calibarea)
          end associate

where frame_flat%data is an associated (yes, tested that) real pointer and average_safe is a boring function that basically averages over non-nan values:


  pure function average_safe_2d(x) result(m)
    use iso_fortran_env, only: int64
    real(fp), intent(in) :: x(:,:)
    real(fp) :: m
    integer :: i, j
    integer(int64) :: n

    m = 0; n = 0
    do j = 1, size(x, 2)
      do i = 1, size(x, 1)
        if (ieee_is_normal(x(i,j))) then
          m = m + x(i,j)
          n = n + 1
        end if
      end do
    end do
    m = m / n
  end function

Making the code to compile with either of them would require changing many, many places in the code for no good reason… so I resigned to just compiling and running my code in a Docker container with gfortran 12, which last seemed to worked. What to do…

Have a sunny day!
Dominik

Could you post a MRE that shows the problem?

Late update, but whatever regression it was between gfortran 12 and 13 that caused these errors, was resolved in 14, and my code now compiles correctly again. I think I just doubted for a moment that choosing Fortran as a way to write long-lasting code that does not obsolete was a good choice. But after update everything seems to be back on track :slight_smile:

I did not post the minimal reproducible example because i could not find one. Any kind of reduction in the code made the error disappear and I failed to produce it – otherwise I would add a gfortran bug.

A pointer error occurs in the associate snippet I posted here: Pure procedure and intent(out) polymorphic pointer argument - #15 by ivanpribec (gfortran accepts it, ifx and flang reject it)

The error about the missing implicit type in gfortran still occurs under some circumstances: 117347 – Associate with derived type array constructor

I hope it will be fixed eventually. (Thanks to all gfortran volunteers!)

1 Like