4
votes

This question is connected to my previous question: How to force compiler to interpret omitted intent as intent(inout) . It appears impossible to interpret omitted intent as intent(inout), so problem of violation of intent(in) is still exists.

The same example:

module test
  implicit none
  contains

  subroutine fun1(x)
    real(8), intent(in)::x
    call fun2(x)               
  end subroutine

  subroutine fun2(x)
   real(8) :: x
   x = 10
  end subroutine
end module

This code can be compiled without any errors/warnings by gfortran and ifort. So my questions is:

How to force fortran compiler to generate an error when intent(in) variable is passed to subroutine with omitted intent ( but with declared interface)?

1
Choose a processor that implements this test/Hassle or pay your vendor to add this feature/modify an existing open source compiler/write your own compiler.IanH

1 Answers

2
votes

As IanH said you need a processor (i.e. compiler) that can pick this up for you. For instance the NAG compiler does (disclaimer - I work for NAG) if you give it the right flags. I modified your code a very little to make it portable and added a driver to show this:

$ cat t.f90 
module test
  implicit none

  Integer, Parameter :: wp = Selected_real_kind( 12, 70 )

  contains

  subroutine fun1(x)
    real(wp), intent(in)::x
    call fun2(x)               
  end subroutine

  subroutine fun2(x)
   real(wp) :: x
   x = 10
  end subroutine
end module

Program test_test

  Use test

  Implicit None

  Real( wp ) :: x

  x = 5.0_wp

  Call fun1( x ) 

End Program test_test
$ nagfor t.f90
NAG Fortran Compiler Release 5.3.1 pre-release(904)
[NAG Fortran Compiler normal termination]
$ ./a.out
$ nagfor -C=all -C=undefined t.f90 
NAG Fortran Compiler Release 5.3.1 pre-release(904)
[NAG Fortran Compiler normal termination]
$ ./a.out
Runtime Error: t.f90, line 15: Dummy argument X is associated with an expression - cannot assign
Program terminated by fatal error
Aborted (core dumped)
$ 

So search the flags, there may be something to help - if not complain to whoever supplies the compiler!