Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Welcome to the Intel Community. If you get an answer you like, please mark it as an Accepted Solution to help others. Thank you!

error with INTENT

New Contributor I

I am using Fortran Compiler .  The following program compiles and runs without any errors.  However, there is a bug because a variable declared as INTENT(in) is passed to a subroutine where it is INTENT(inout).  Can the latest version of the compiler catch this bug?


module mymod
   pure subroutine myplus( a, b, c )
   implicit none
   integer,intent(inout):: a   !!!
   integer,intent(in):: b
   integer,intent(out):: c
      a = a * 2
      c = a + b
   end subroutine myplus
   pure function myadd( a, b ) result(c)
   implicit none
   integer,intent(in):: a, b
   integer c
      call myplus( a, b, c )  ! ERROR: a is intent(in), goes to intent(inout)
   end function myadd

end module mymod
program test_intent
use mymod, only: myadd
implicit none
integer a, b
   a = 1
   b = 2
   write(*,*) myadd(a, b)
end program test_intent


0 Kudos
0 Replies