长度参数化的传递对象到类型绑定过程有 gfortran 抱怨 [英] Length-parameterized passed object to type-bound procedure has gfortran complain
问题描述
我正在学习 Fortran,我想将一个数组和一个子例程封装在一个类型中.问题似乎出在自对象的类型定义中.
I'm learning Fortran and I'd like to encapsulate an array and a subroutine in a type. The problem appears to be in the type definition of the self-object.
这是我想出的最小测试用例:
This is the minimal test case I came up with:
module testing
implicit none
type test(para)
integer, len :: para
real, dimension(para) :: weights
contains
procedure :: testing => testing_test
end type
contains
subroutine testing_test(self)
class(test(*)) :: self
end subroutine
end module
用 gfortran 编译会引发这个错误:
Compiling this with gfortran raises this error:
module_test.f08:9:23:
procedure :: testing => testing_test
1
Error: Argument ‘self’ of ‘testing_test’ with PASS(self) at (1) must be of the derived-type ‘test’
当数组长度固定时有效(所以 type%para
不存在)
It works when the array-length is fixed (so type%para
doesn't exist)
我正在尝试做的事情(类型可变大小和绑定过程的数组)是完全不可能的,还是我遗漏了一些关于虚拟参数定义的内容?
Is what I'm trying to do (type with array of variable size and bound procedure) plain impossible or am I missing something regarding dummy argument definition?
推荐答案
感谢@Rodrigo 的想法,我终于找到了这个错误(和补丁):https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82943
Thanks to @Rodrigo for the idea, I finally found this bug (and patch): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82943
要解决此问题,请下载源代码,应用上述补丁并编译您自己的 gfortran.(或者等到它在存储库中)
To fix the issue, download the source, apply the mentioned patch and compile your own gfortran. (Or wait until it's in the repositories)
这篇关于长度参数化的传递对象到类型绑定过程有 gfortran 抱怨的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!