这个问题与我之前的问题有关:如何强制编译器将省略的意图解释为意图(inout)。将省略的意思表示为意思表示似乎是不可能的,所以违反意思表示的问题仍然存在。
同样的例子:
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
gfortran和ifort可以在没有任何错误/警告的情况下编译此代码。所以我的问题是:
当intent(in)变量传递到带有省略意图(但带有声明接口)的子例程时,如何强制fortran编译器生成错误?
正如IanH所说,您需要一个处理器(即编译器)来为您处理这些问题。例如,如果你给它正确的标志,NAG编译器就会这样做(免责声明-我为NAG工作)。我修改了你的代码,使其可移植,并添加了一个驱动程序来显示:
$ 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)
$
因此,搜索这些标志,可能会有所帮助——如果不是向提供编译器的人投诉的话!