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

Automatic allocation failing when casting from integer to real(dp)

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

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 版本进行了修复。