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

Missing warning for dummy argument with an explicit INTENT(OUT) being used before it is defined.

FortranFan
Honored Contributor III
2,743 Views

Consider the following simple code snippet.  Intel Fortran does give a warning if the procedure does not give a value to a dummy argument with an explicit INTENT(OUT) attribute.  However a warning if such a variable is used before being defined is missing; it'll be very helpful if the compiler can warn for this situation as well.

module m

   implicit none

contains

   subroutine foo(i)

      integer, intent(out) :: i

      print *, i

      return

   end subroutine foo

   subroutine bar(i)

      integer, intent(out)  :: i

      print *, i
      
      i = 1

      return

   end subroutine bar

end module m
Compiling with Intel(R) Visual Fortran Compiler XE 15.0.3.208 [Intel(R) 64]...
m.f90
C:\..\m.f90(7): warning #6843: A dummy argument with an explicit INTENT(OUT) declaration is not given an explicit value.   

Build log written to  "file://C:\..\temp\Release\x64\p_BuildLog.htm"
p - 0 error(s), 1 warning(s)

 

0 Kudos
4 Replies
mecej4
Honored Contributor III
2,743 Views

The warning that you did get is helpful, and the warning that you wish to see (but did not) would also be helpful, but compilers are easily mollified into not giving warnings when they see token assignments made with code such as the following.

If, prior to the PRINT statement on Line-9, you add "if(.false.)i = 77", the warning will go away, even though the variable i continues to be undefined.

0 Kudos
jimdempseyatthecove
Honored Contributor III
2,743 Views

Oh, and print or write may not catch the intent out thing, whereas an assignment statement with the not yet used intent(out) variable on rhs may be more picky.

Jim Dempsey

0 Kudos
andrew_4619
Honored Contributor III
2,743 Views

My take is that I think the checking gives the warning only if it finds no assignment to an intent out arg which is relatively simple to do. To do more in general would get pretty complicated where there are multiple paths through the code and the assignment may or may not be happen.  In some cases it would be only possible to determine this at run-time and there is a run-time check that can do this,

Whilst I agree such an error message might be helpful I suspect the effort required to achieve this (in the cases where is is possible) might be rather more effort than it is worth,

 

0 Kudos
Andrew_Smith
Valued Contributor I
2,743 Views

Only local scalar variables are currently checked for uninitialized before use.

0 Kudos
Reply