将可选的可分配数组与可选的不可分配的虚拟参数相关联时出现分段错误

Segmentation fault when associating optional allocatable array with optional non-allocatable dummy argument

以下 Fortran 代码在 SLES 15 上使用未经优化 (-O0) 的 ifort 版本 19.0.3.199 编译时会生成分段错误:

program test_prg
  call sub1()

contains

  subroutine sub1(opt)
    integer, allocatable, optional :: opt(:)
    call sub2(opt)
  end subroutine

  subroutine sub2(opt)
    integer, optional :: opt(:)
  end subroutine

end program

我不打算在 sub2 中分配 opt,所以我没有在那里指定 allocatable 属性。如果我使它在两个子例程或非可选中都可分配,或者如果我在对 sub1 的调用中传递了实际参数,那么代码将无错地完成。从 gcc 版本 8.3.0 20190222 使用 gfortran 编译时,相同的代码也可以正常运行。

这是编译器错误还是我在这里做了一些非法的事情?

Fortran 2018 禁止您在 sub1 中使用 opt。对不存在的可选伪参数的限制包括 (15.5.2.12):

An optional dummy argument that is not present is subject to the following restrictions.

...

(8) If it is allocatable, it shall not be allocated, deallocated, or supplied as an actual argument corresponding to an optional nonallocatable dummy argument.