Gfortran 10 添加了默认行为,使类型不匹配成为错误而不是警告。标志
-fallow-argument-mismatch
可用于将错误降级为警告。然而,在同一个 fortran 文件中,并使用带有 -fallow-argument-mismatch
的 gcc 13,gfortran 会发出一些警告(如预期),并在此处发出一个错误:
call test(ter,file,0,'legacy')
subroutine test(ander,file,mmr,status)
implicit none
integer(kind=8) :: mmr
....
为什么这种特殊的不匹配在某种程度上有所不同,而不被视为警告?
我可以通过这样做来解决这个问题:
call test(ter,file,INT8(0),'legacy')
但是,我认为这就是在编译时使用
-fallow-argument-mismatch
的原因。我的编译命令如下:
gfortran -mfma -O3 -m64 -Ofast -ftree-vectorize -ftree-vectorizer-verbose=0 -fPIC -ffree-form -ffree-line-length-none -fallow-invalid-boz -fallow-argument-mismatch -fbackslash -fno-fast-math -c mem.f90 -o mem.o
mmr
中期望的是整数 0,1,>1 或 <0.
类型不匹配违反了 Fortran 标准的程序单元限制。编译器不需要能够检测和报告此类违规行为,但可以选择这样做。
考虑(非 Fortran)程序:
program broken
implicit none(external)
external sub
call sub(1)
call sub(1.)
end program
这违反了 Fortran 标准关于过程引用的(长期存在的)规则,许多编译器会告诉您这一点。从 GCC 10 开始,gfortran 默认会抱怨这一点,并提供选项
-fallow-argument-mismatch
来允许仍然编译许多损坏的 Fortran 源代码,就像早期版本的 gfortran 编译它们一样。1
-fallow-argument-mismatch
选项描述为:
-fallow-argument-mismatch
Some code contains calls to external procedures with
mismatches between the calls and the procedure
definition, or with mismatches between different
calls. Such code is non-conforming, and will usually
be flagged wi1th an error. This options degrades the
error to a warning, which can only be disabled by
disabling all warnings vial -w. Only a single
occurrence per argument is flagged by this warning.
-fallow-argument-mismatch is implied by -std=legacy.
注意“外部”。
非 Fortran 源代码
program brokeninternal
implicit none
call sub(1)
contains
subroutine sub(x)
real x
end subroutine sub
end program brokeninternal
类型不匹配,并且不使用
-fallow-argument-mismatch
不会让你逃脱惩罚。过程sub
是内部的,因此具有显式接口2;编译器使用显式接口来检查参数。 “yonks”的类型可以追溯到显式接口出现的时候。没有遗漏诊断或非法但有用的使用来支持。
1 无论是否违反 Fortran 标准,此类损坏的 Fortran 程序都是有用的。其他已抱怨多年的 Fortran 编译器仍然让用户坚持编译它们。
外部过程可能有显式接口,并且
-fallow-argument-mismatch
不允许这种不匹配。在某些情况下,gfortran(现在)可以检测与隐式接口的特征不匹配,特别是当外部过程与引用它的位置在同一文件中定义时,并且 -fallow-argument-mismatch
可能会产生影响。