https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93263
--- Comment #6 from markeggleston at gcc dot gnu.org --- (In reply to Tobias Burnus from comment #5) > (In reply to markeggleston from comment #4) > > - if (ns->save_all || !flag_automatic) > > + if (!recursive && (ns->save_all || !flag_automatic)) > > > Does the trick. Now need to write the test cases and prepare a patch. > > I wonder whether it should be rather: > if (ns->save_all || (!flag_automatic && !recursive)) That's clearer. > > I think your patch would break for the following code. And I believe it is > standard conform Fortran 90/2018: I'll check and reconsider if it does. > > integer :: cnt > cnt = 0 > call sub() > if (cnt /= 5) stop 1 > contains > recursive subroutine sub() > save > logical :: first = .true. > integer :: i > cnt = cnt + 1 > if (first) then > first = .false. > i = 1 > end if > print *, "Hello", i > i = i + 1 > if (i <= 5) call sub() > end subroutine > end > > * * * > > Side remark: The Fortran 2018 introduction states: > > "the RECURSIVE keyword is advisory only. The NON_RECURSIVE keyword specifies > that a procedure is not recursive." > > Hence, I wonder whether this is correctly implemented in gfortran …