Oop 与Fortran子模块和gcc兼容标志混淆-Wuse不带
此gcc Fortran编译警告的补救措施是什么Oop 与Fortran子模块和gcc兼容标志混淆-Wuse不带,oop,gcc,module,fortran,gfortran,Oop,Gcc,Module,Fortran,Gfortran,此gcc Fortran编译警告的补救措施是什么 USE statement at (1) has no ONLY qualifier 在gcc 6.0、6.1、6.2和7.0中使用子模块时会出现警告 完整的编译顺序和警告: $ gfortran -c -Wuse-without-only -o mod_module.o mod_module.f08 $ gfortran -c -Wuse-without-only -o mod_module_sub.o mod_module_sub.f08
USE statement at (1) has no ONLY qualifier
在gcc 6.0、6.1、6.2和7.0中使用子模块时会出现警告
完整的编译顺序和警告:
$ gfortran -c -Wuse-without-only -o mod_module.o mod_module.f08
$ gfortran -c -Wuse-without-only -o mod_module_sub.o mod_module_sub.f08
mod_module_sub.f08:1:19:
submodule ( mModule ) mSubModule
1
Warning: USE statement at (1) has no ONLY qualifier [-Wuse-without-only]
$ gfortran -c -Wuse-without-only -o demonstration.o demonstration.f08
$ gfortran -o demonstration demonstration.o mod_module.o mod_module_sub.o
$ ./demonstration
this + that = 3.00000000
expected value is 3
主程序(演示。f08):
模块(模块f08):
子模块(模块f08):
子模块(mModule)mSubModule 根据您的观点,这只是一个编译器错误。提交一个bug报告并等待修复(或者自己修复)
(另一种观点是,由于该代码允许子模块访问其主机的所有实体(无论是否需要),因此警告是适当的。但限制主机关联需要F2015支持。)
-Wuse with only
只是一个警告,有助于强制实施特定的编程风格(我认为这种风格不是特别有用)。编译任何短代码或长代码都不是“必要的”。如果警告同时困扰您,请删除该选项。我的任何代码都不会在没有警告的情况下通过该选项。
program demonstration
use mModule, only : myType
implicit none
type ( myType ) :: example
example % this = 1.0
example % that = 2.0
call example % adder ( )
write ( *, * ) 'this + that = ', example % other
write ( *, * ) 'expected value is 3'
stop
end program demonstration
module mModule
implicit none
type :: myType
real :: this, that, other
contains
private
procedure, public :: adder => adder_sub
end type myType
private :: adder_sub
interface
module subroutine adder_sub ( me )
class ( myType ), target :: me
end subroutine adder_sub
end interface
end module mModule
submodule ( mModule ) mSubModule ! <=== problematic statement
implicit none
contains
module subroutine adder_sub ( me )
class ( myType ), target :: me
me % other = me % this + me % that
end subroutine adder_sub
end submodule mSubModule