Silverfrost Forums

Welcome to our forums

error 474 - Invalid expression in array constructor

9 Jan 2025 2:22 #31803

I think the error reported by the compiler in this case is not correct.

I don't understand how an implied do loop / array constructor can reference an intrinsic function, but not a function defined elsewhere in the code.

Any ideas/explanations welcome.

Ken

module demo_problem2
implicit none
contains
  elemental function squareD (x) result (returnval)
  real*8, intent(in) :: x
  real*8 :: returnval
    returnval = x*x
  end function squareD
end module demo_problem2

program p2
use demo_problem2
implicit none
integer, parameter :: n = 5
integer :: i
real*8 :: a(n)

!  forall (i = 1:n:1)               ! This works with FTN95, for elemental squareD
!    a(i) = squareD(dble(i))
!  end forall

!  do i = 1, n                      ! This works with FTN95 
!    a(i) = squareD(dble(i))
!  end do

!   a = [(sin(dble(i)),i=1,n,1)]    ! This works with FTN95 - when referencing an intrinsic function

  a = [(squareD(dble(i)),i=1,n,1)] ! This does not work with FTN95 - when referencing an non-intrinsic function
                                   ! error 474 - Invalid expression in array constructor
  do i = 1, size(a)
    print*, i, a(i)
  end do
  
end program p2
9 Jan 2025 7:17 #31804

Ken

Thank you for the feedback. This looks like a bug that needs fixing.

5 May 2025 12:06 #32099

This failure has now been fixed for the next release of FTN95.

Please login to reply.