https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120483
Bug ID: 120483 Summary: character(len=:), allocatable, save variable returns incorrect substring Product: gcc Version: 15.1.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: peter at guentert dot com Target Milestone: --- When using a deferred-length allocatable character variable with the SAVE attribute, substring references give incorrect results. Test case: --------------------------------------- program test character(len=:), allocatable, save :: s1 character(len=:), allocatable :: s2 s1 = 'ABC' print *, 's1='//s1//', s1(3:3)='//s1(3:3) s2 = 'ABC' print *, 's2='//s2//', s2(3:3)='//s2(3:3) end --------------------------------------- Expected Output: s1=ABC, s1(3:3)=C s2=ABC, s2(3:3)=C Actual Output (gfortran 15.1.0): s1=ABC, s1(3:3)=A s2=ABC, s2(3:3)=C Compiler Version: $ gfortran --version GNU Fortran (Homebrew GCC 15.1.0) 15.1.0 System: MacOS Sequoia 15.5 (24F74) Homebrew 4.5.3 $ gcc --version Apple clang version 17.0.0 (clang-1700.0.13.5) Target: arm64-apple-darwin24.5.0 Thread model: posix InstalledDir: /Library/Developer/CommandLineTools/usr/bin $ uname -a: Darwin ... 24.5.0 Darwin Kernel Version 24.5.0: Tue Apr 22 19:54:49 PDT 2025; root:xnu-11417.121.6~2/RELEASE_ARM64_T6000 arm64 Notes: - Removing `SAVE` from `s1` makes it behave correctly. - gfortran 13.3.0 and Intel compilers give correct results.