Problem with Allocatable character module variable with gfortran 15.1

Dear All,

After upgrading gfortran on my Mac from 14.2 to 15.1, some of my codes no longer work properly. I have isolated the problem and been able to reproduce it in a minimal test given below. I have reported the bug on Bugzilla, but in the meantime, it would be great if someone could tell me whether the same behaviour is observed on platforms other than Mac.

module bar1_m
   ! bug with gfortran 15.1 when str is an allocatable module variable
   character(len=:), allocatable :: str
   character(len=:), allocatable :: s1, s2 
contains
   subroutine bar1
      str = 'gfortran15.1.0' ; s1 = str(1:8) ; s2 = str(9:)
      print*, "in bar1: str="//str//"  compiler="//s1//"  version="//s2
   end subroutine bar1
end module bar1_m

module bar2_m
   ! No problem when str is not a module variable
   character(len=:), allocatable :: s1, s2
contains
   subroutine bar2
      character(len=:), allocatable :: str
      str = 'gfortran15.1.0' ; s1 = str(1:8) ; s2 = str(9:)
      print*, "in bar2: str="//str//"  compiler="//s1//"  version="//s2
   end subroutine bar2
end module bar2_m

module bar3_m
   ! No problem when str is a constant module variable
   character(len=*), parameter   :: str = 'gfortran15.1.0'
   character(len=:), allocatable :: s1, s2
contains
   subroutine bar3
      s1 = str(1:8) ; s2 = str(9:)
      print*, "in bar3: str="//str//"  compiler="//s1//"  version="//s2
   end subroutine bar3
end module bar3_m

program foo
   use bar1_m ; use bar2_m ; use bar3_m
   call bar1 ; call bar2 ; call bar3
end program foo

! With gfortran-15:   
!   in bar1: str=gfortran15.1.0  compiler=gfortran  version=gfortr 
!   in bar2: str=gfortran15.1.0  compiler=gfortran  version=15.1.0 
!   in bar3: str=gfortran15.1.0  compiler=gfortran  version=15.1.0 
! With gfortran-14: OK
3 Likes

Same on Void Linux plus Homebrew for Linux. A very strange bug. str is OK but str(9:14) or even simpler str(9:9) is not.

Thank you msz59. According to the response given on Bugzilla (Making sure you're not a bot!), this bug has been fixed in versions >= 15.1.1. However, these versions are not yet available with Homebrew.