https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68778
Bug ID: 68778 Summary: Missing default initialization of finalized derived types type(C_PTR) component in subroutines Product: gcc Version: 5.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: baradi09 at gmail dot com Target Milestone: --- When having a derived type with a type(C_PTR) component, which is default initialized to C_NULL_PTR, the default initialization is not carried out, when the derived type is declared within a subroutine, provided the derived type has a final method. The self containing example below demonstrates the problem. module testmod use, intrinsic :: iso_c_binding implicit none type :: testtype type(C_PTR) :: ptr = C_NULL_PTR contains ! If final binding is commented out here, the example works correctly final :: destroy end type testtype contains subroutine destroy(tt) type(testtype), intent(inout) :: tt continue end subroutine destroy subroutine test() type(testtype) :: aa print *, "TEST2: ASSOCIATED? (EXPECT: F)", c_associated(aa%ptr) end subroutine test end module testmod program showbug use testmod implicit none call test() end program showbug