You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

gfortran中子模块隐式USE无ONLY限定符的警告是否为误报?

关于gfortran子模块-Wuse-without-only警告的问题

当使用命令gfortran -Wuse-without-only greeting.f90编译以下Fortran代码时:

module greet_m

  implicit none

  interface
     module subroutine hello (name)
       character (len=*), intent (in), optional :: name
     end subroutine hello
  end interface

end module greet_m

submodule (greet_m) greet_implementation_sm

contains

  module subroutine hello (name)
    character (len=*), intent (in), optional :: name

    if (present (name)) then
       print '("Hello ", a, "!")', name
    else
       print '("Hello World!")'
    end if
  end subroutine hello

end submodule greet_implementation_sm

program greeting

  use greet_m, only: hello

  implicit none

  call hello
  call hello ('John')

end program greeting

gfortran 14.1(x86_64架构Arch Linux系统)给出如下警告:

greeting.f90:13:19:

   13 | submodule (greet_m) greet_implementation_sm
      |                   1
Warning: USE statement at (1) has no ONLY qualifier [-Wuse-without-only]

子模块本身就需要隐式导入父模块的所有符号,这是Fortran标准规定的正常行为——gfortran在这里确实是误报了警告,因为用户根本没有手动写use greet_m语句,而是编译器内部隐式处理的逻辑,不该触发-Wuse-without-only的检查。

这种情况应该提交bug反馈给gfortran开发团队。

内容的提问来源于stack exchange,提问作者Ghorban M. Tavakoly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.21 22:48:11