fortran - 从整数转换为实数(dp)时自动分配失败

标签 fortran gfortran fortran2003

我不知道我是遇到编译器错误还是遗漏了什么。我正在尝试运行以下代码:

program test
  implicit none

  integer, parameter :: dp=kind(1.d0)

  integer,  allocatable :: int_mat(:,:)
  integer,  allocatable :: int_mat_2(:,:)
  real(dp), allocatable :: real_mat(:,:)

  allocate(int_mat(2,2))
  int_mat = 0
  int_mat_2 = int_mat
  real_mat = int_mat ! Falls over here.
end program

编译运行 nagfor (flags: -f2003 -C=all)按预期工作。编译运行 gfortran (flags: -std=f2003 -fcheck=all)运行时失败并显示错误消息:
At line 13 of file test.f90
Fortran runtime error: Array bound mismatch for dimension 1 of array 'real_mat' (1/2)

我希望代码成功,如 int_mat_2real_mat应该隐式分配。这对于 int_mat_2 来说似乎是正确的但不适用于 real_mat .

我已经用各种 gfortran 版本(5.4、6.3、7.0)尝试过这个,并且都有同样的问题。

最佳答案

由 francescalus 发现,这是 this compiler bug ,此后已针对更新的 gfortran 版本进行了修复。

关于fortran - 从整数转换为实数(dp)时自动分配失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46039931/

相关文章:

performance - 'recursive' 属性如何影响 FORTRAN90 子例程的性能

makefile - Fortran Makefile 中目标文件 "*.o"的自动排序

Java Swing 执行 gFortran 代码

fortran - 当类型在编译时已知时,是否有额外的开销调用具有多态派生类型的子例程?

fortran - Fortran 的 "final"子程序在实际使用中是否足够可靠?

arrays - 在Fortran中访问返回数组的元素

linux - Windows 下 Cygwin 的执行速度比 VirtualBox 中 Linux 的执行速度慢

parallel-processing - 不带选项的 mpirun 仅在一个进程上运行程序

fortran - 在 Fortran DLL 中调用 RANDOM_NUMBER

c - 从 C 库头自动生成 Fortran 2003 绑定(bind)(使用 iso_c_bindings 内部模块)