https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103394
Bug ID: 103394 Summary: Bad object code for structure constructor Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: neil.n.carlson at gmail dot com Target Milestone: --- Bad object code is being generated for the structure constructor expression in the example below. This occurs for the current 12.0 trunk and any of the earlier 9.x, 10.x and 11.x versions I've tried. It seems that things go wrong with the expression foo_vector_func(this) when both the foo_vector_func type is an extension and the variable this is also polymorphic. module foo_type type :: foo contains procedure :: alloc_foo_vector_func end type type, abstract :: vector_func end type type, extends(vector_func) :: foo_vector_func type(foo), pointer :: ptr end type contains subroutine alloc_foo_vector_func(this, vf) class(foo), intent(in), target :: this class(vector_func), allocatable, intent(out) :: vf allocate(vf, source=foo_vector_func(this)) ! DOESN'T WORK CORRECTLY !vf = foo_vector_func(this) ! DOESN'T WORK EITHER end subroutine end module program main use foo_type type(foo), target :: x class(vector_func), allocatable :: vf call x%alloc_foo_vector_func(vf) select type (vf) type is (foo_vector_func) if (.not.associated(vf%ptr, x)) stop 1 ! SHOULD NOT EXIT HERE end select end program