https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125568
Bug ID: 125568
Summary: Invalid character error in array initialization
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: fortran
Assignee: unassigned at gcc dot gnu.org
Reporter: ivan.pribec at gmail dot com
Target Milestone: ---
The program attached below fails to compile with the error,
$ gfortran -Wall factorial_power.f90 && ./a.out
factorial_power.f90:35:18:
35 | reshape([([(product([(ic, ic=j-k+1, j)]), j=0, nmax)], k=0,
nmax)], &
| 1
Error: Invalid character in name at (1)
Works with flang, NAG and ifx.
! factorial_power.f90 -- Reproducer for GCC bugzilla
!
! Tests parameter array initialisation via implied-do in a contained function.
!
program main
implicit none
integer, parameter :: nmax = 12
integer :: j, k, fact
! Property 1: (j)_j = j! (diagonal of table equals factorial)
fact = 1
do j = 0, nmax
if (j > 0) fact = fact * j
if (factorial_power(j, j) /= fact) error stop 1
end do
! Property 2: recurrence (j)_k = (j)_{k-1} * (j - k + 1) for 1 <= k <= j
do j = 1, nmax
do k = 1, j
if (factorial_power(j, k) /= factorial_power(j, k-1) * (j - k + 1)) &
error stop 2
end do
end do
contains
! The falling power (falling factorial, Pochhammer symbol) is:
! (x)_n = x * (x - 1) * ... * (x - n + 1) ! product of n terms
! with the convention (x)_0 = 1 (empty product).
function factorial_power(x, n) result(ic)
integer, intent(in) :: x, n
integer :: ic, j, k
integer, parameter :: c(0:nmax, 0:nmax) = &
reshape([([(product([(ic, ic=j-k+1, j)]), j=0, nmax)], k=0, nmax)], &
shape=[nmax+1, nmax+1])
if (x < 0 .or. x > nmax) error stop "invalid x"
if (n < 0 .or. n > nmax) error stop "invalid n"
ic = c(x, n)
end function
end program