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

时间:2017-09-04 15:12:18

标签: 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),并且都有同样的问题。

1 个答案:

答案 0 :(得分:0)

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