2017-01-25 71 views
1

此gcc Fortran編譯警告的補救措施是什麼?與Fortran子模塊和gcc compliation標誌混淆-Wuse-without-only

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 

主程序(demonstration.f08):

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 

模塊(mod_module.f08):

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 

子模塊(mod_module_sub .f08):

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 

也就是說,指定子模塊的正確方法是什麼?標記-Wuse-without-only對編譯較長代碼至關重要。

回答

2

根據你的觀點,這只是一個編譯器錯誤。提交錯誤報告並等待它得到修復(或自行修復)。

(另一種觀點是,因爲該代碼給子模塊訪問其主機的所有實體,無論是否需要,該警告是恰當的。但是,限制主機的關聯需要F2015支持。)

-Wuse-without-only只是一個警告,以幫助強制執行特定的編程風格(我認爲這不是特別有用)。編譯任何短或長的代碼都不是「必需的」。如果警告在此期間困擾您,請刪除該選項。

+0

我的任何代碼都不會在沒有警告的情況下通過該選項。 –