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

error with INTENT

Roman1
New Contributor I
367 Views

I am using Fortran Compiler 18.0.3.210 .  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
   contains
   
   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
   return
   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)
   return
   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)
stop
end program test_intent

 

0 Kudos
0 Replies
Reply