Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.

SUM() not accepted in constant expression

Harald
Beginner
522 Views

Hello,

the following code appears to be valid, but ifort rejects it:

program ifort_sum_param
  implicit none
  real, parameter :: a(3) = [ 1., 2., 3. ]
  real, parameter :: b = sum (a)
  print *, b
end

I get:

% ifort -V ifort-sum.f90 
Intel(R) Fortran Compiler XE for applications running on IA-32, Version 15.0.3.187 Build 20150407
Copyright (C) 1985-2015 Intel Corporation.  All rights reserved.
FOR NON-COMMERCIAL USE ONLY

 Intel(R) Fortran 15.0-1812
ifort-sum.f90(4): error #6263: This intrinsic function is invalid in constant expressions.   [SUM]
  real, parameter :: b = sum (a)
-------------------------^
compilation aborted for ifort-sum.f90 (code 1)

As far as I can tell, and by looking at the F2008 standard, section 7.1.12 (constant expression), there is no exclusion for SUM() to be used here.

The above code is accepted by the GNU and Cray compilers.

 

0 Kudos
3 Replies
Lorri_M_Intel
Employee
522 Views

It works in the 16.0 beta compiler; we hadn't quite gotten to that one for the 15.0 stream.

               --Lorri

0 Kudos
JVanB
Valued Contributor II
522 Views

This was also discussed in https://software.intel.com/en-us/forums/topic/495001 where a longer list of transformational intrinsics was tested. I exchanged emails with Steve on this topic roughly 2/9/15 but can't recall whether it got a case number or not. Good to see that some of them at least will be fixed in 16.0.

 

0 Kudos
Steven_L_Intel1
Employee
522 Views

All of the intrinsic functions that F2003 says are valid in initialization expressions should work in 16.0. We have an open issue on IEEE_SELECTED_REAL_KIND from IEEE_ARITHMETIC, but we're working on that.

0 Kudos
Reply