lfortran icon indicating copy to clipboard operation
lfortran copied to clipboard

Substring as an initial data target, character(len=3), pointer :: p => t(2:4), is rejected: "must reduce to a compile time constant"

Open usefahmed07 opened this issue 1 month ago • 0 comments

A character pointer initialized at declaration to a substring of a target variable (a valid initial data target) is rejected. GFortran accepts it.

program sp3
  implicit none
  character(len=5), target :: t = "abcde"
  character(len=3), pointer :: p => t(2:4)
  print *, p
end program
$ lfortran sp3.f90
ASR verify pass error: Initialisation of p must reduce to a compile time constant.
 --> sp3.f90:4:32

The same happens with character(len=:), pointer :: p => t(2:4). When the declaration is inside a module procedure that uses a module-level target variable, it additionally ends with "Internal Compiler Error: Unhandled exception".

Expected: prints bcd (GFortran).

Found via the gfortran testsuite, gfortran.dg/char_pointer_substring_init.f90. Related but different: #15181 (array element as an initial data target).

Version: 0.68.0-61-gcb859775a5

usefahmed07 avatar Oct 27 '26 09:10 usefahmed07