`ifort` and `ifx`: "This variable has not been used"?

Is there anything wrong with the following piece of code? On Ubuntu 20.04 (linux 5.4.0-91-generic), both ifort and ifx from Intel oneAPI 2021.2.0 or 2022.0.1 give me a warning as follows.

$ ifort -warn all test_intel.f90 
test_intel.f90(16): remark #7712: This variable has not been used.   [X]
function foo(fun, n) result(x)
----------------------------^
$ ifx -warn all test_intel.f90 
test_intel.f90(16): remark #7712: This variable has not been used.   [X]
function foo(fun, n) result(x)
----------------------------^

Code:

! test_intel.f90
module test_intel_mod
implicit none
private
public :: foo, bar, fun

abstract interface
    function FCN(x) result(f)
    implicit none
    real, intent(in) :: x
    real :: f
    end function FCN
end interface

contains

function foo(fun, n) result(x)
implicit none
procedure(FCN) :: fun
integer, intent(in) :: n
real :: x
real :: fval(n)
fval = 0.0
x = fun(0.0) + sum(fval) + real(n)
end function foo

function bar(fun, n) result(x)
implicit none
procedure(FCN) :: fun
integer, intent(in) :: n
real :: x
x = fun(0.0) + real(n)
end function bar

function fun(x) result(f)
implicit none
real, intent(in) :: x
real :: f
f = x
end function fun

end module test_intel_mod

program test_circle
use, non_intrinsic :: test_intel_mod, only : foo, fun
implicit none
real :: x
x = foo(fun, 1)
print *, x
end program test_circle

Thank you very much!

No, there does not seem to be anything wrong. I have tried some variations on this code (adding the recursive keyword, with or without fval, …) and sometimes the message disappears and sometimes it pops up. I cannot discern a pattern, but your code clearly sets the result variable and therefore that message is false. (gfortran does not warn about it not being used by the way)

1 Like

Thank you, @Arjen, for the reassuring response and the tests.

I have reported it to Intel, looking forward to a fix.

2 Likes

The option -warn nounused can be useful with ifort.

1 Like

I used -warn:all (on Windows) for Intel Fortran and -Wall for gfortran.