Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
24 Views

error with INTENT

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