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

Problems with constant expressions

MR
Beginner
444 Views

Hi,

consider the following code:

program p

 implicit none

 logical, parameter :: use_v1 = .true.
 integer, parameter :: v1 = 3, v2 = 8
 integer, parameter :: &
  ! this produces a warning at compile time and wrong result
   i = v1*count( (/use_v1/) ) + v2*count( (/.not.use_v1/) )
  ! this produces an ICE at compile time
  !i = v1*count( (/use_v1/) ,kind=kind(i)) + v2*count( (/.not.use_v1/) )

 write(*,*) i

end program p

Compiling with

ifort -stand f08 p.f90 -o p

I see two warnings and wrong results at run time (-3 instead of 3)

$ ifort -stand f08 p.f90 -o p
p.f90(9): warning #6192: Fortran 2008 does not allow this data type conversion.
   i = v1*count( (/use_v1/) ) + v2*count( (/.not.use_v1/) )
----------^
p.f90(9): warning #6192: Fortran 2008 does not allow this data type conversion.
   i = v1*count( (/use_v1/) ) + v2*count( (/.not.use_v1/) )
-----------------------------------^
$ ./p
          -3

Isn't the code right? In any case, I don't understand which type conversion is intended here.

Using the commented line, where the kind is specified, I see an internal compiler error.

$ ifort -V
Intel(R) Fortran Intel(R) 64 Compiler XE for applications running on Intel(R) 64, Version 15.0 Build 20150121

Thanks, Marco

0 Kudos
3 Replies
Steven_L_Intel1
Employee
444 Views

The "wrong result' is a bug we recently fixed. I'll make sure the standards warning and internal compiler error get addressed as well. Thanks. Issue ID is DPD200366418 (the "wrong result" issue is DPD200366183.)

0 Kudos
MR
Beginner
444 Views

OK, thank you. Marco

0 Kudos
Steven_L_Intel1
Employee
444 Views

These problems have been fixed in our sources - I expect the fix to be included in 15.0 Update 3.

0 Kudos
Reply