我正在尝试实现一个简单的终结器,但我甚至无法编译this example:
MODULE m
TYPE :: t1
REAL a,b
END TYPE
TYPE, EXTENDS(t1) :: t2
REAL,POINTER :: c(:),d(:)
CONTAINS
FINAL :: t2f
END TYPE
TYPE, EXTENDS(t2) :: t3
REAL,POINTER :: e
CONTAINS
FINAL :: t3f
END TYPE
CONTAINS
SUBROUTINE t2f(x) ! Finalizer for TYPE(t2)'s extra components
TYPE(t2) :: x
print *, 'entering t2f'
IF (ASSOCIATED(x%c)) then
print *, ' c allocated, cleaning up'
DEALLOCATE(x%c)
end if
IF (ASSOCIATED(x%d)) then
print *, ' d allocated, cleaning up'
DEALLOCATE(x%d)
end if
END SUBROUTINE
SUBROUTINE t3f(y) ! Finalizer for TYPE(t3)'s extra components
TYPE(t3) :: y
print *, 'entering t3f'
IF (ASSOCIATED(y%e)) then
print *, ' e allocated, cleanup up'
DEALLOCATE(y%e)
end if
END SUBROUTINE
END MODULE
使用GNU Fortran(GCC)4.8.2 20131212(Red Hat 4.8.2-7)给出了这个错误输出:
$ gfortran -c m_example.f03 m_example.f03:5.26:
TYPE,EXTENDS(t1):: t2 1错误:(1)的终结尚未实现m_example.f03:10.26:
TYPE,EXTENDS(t2):: t3 1错误:(1)的终结尚未实施
这是一个错误,是否意味着终结者还没有在gfortran中实现,或者我做错了什么?
答案 0 :(得分:2)
从gcc 4.9开始,终结器被识别出来。此外,如果您不自己实现它们,编译器似乎会生成终结代码本身。
不幸导致bug 59765。仍然可以在gcc gfortran 4.10中找到,因为我不幸发现。