Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29279 Discussions

Structure constructor expects value for default-initialized component (from an abstract type)

jwmwalrus
New Contributor I
862 Views

Hi.

I'm somewhat confused by the following code:

module mod1
    implicit none
    private

    type, abstract, public :: required
    contains
        procedure(i_proc1), deferred, pass(this) :: proc1
        procedure(i_proc2), deferred :: proc2
    end type

    abstract interface
        pure subroutine i_proc1(data, string, this)
            import
            class(*), intent(inout) :: data
            character(*), intent(in) :: string
            class(required), intent(inout) :: this
        end subroutine

        pure subroutine i_proc2(this, string, DATA)
            import
            class(required), intent(in) :: this
            character(:), allocatable, intent(inout) :: string
            class(*), optional, intent(in) :: DATA
        end subroutine
    end interface
    public :: i_proc1
    public :: i_proc2
end module mod1

module mod2
    use mod1

    implicit none
    private

    type, extends(required), public :: child
    ! type, public :: child
        integer :: offset = 0
        logical :: valid = .false.
    contains
        procedure, pass(this) :: proc1 => child_proc1
        procedure :: proc2 => child_proc2
    end type

    interface
        module pure subroutine child_proc1(data, string, this)
            class(*), intent(inout) :: data
            character(*), intent(in) :: string
            class(child), intent(inout) :: this
        end subroutine

        module pure subroutine child_proc2(this, string, DATA)
            class(child), intent(in) :: this
            character(:), allocatable, intent(inout) :: string
            class(*), optional, intent(in) :: DATA
        end subroutine
    end interface

    type, extends(required), public :: parent
    ! type, public :: parent
        character(:), allocatable :: name
        type(child) :: ch
    contains
        procedure, pass(this) :: proc1 => parent_proc1
        procedure :: proc2 => parent_proc2
    end type

    interface
        module pure subroutine parent_proc1(data, string, this)
            class(*), intent(inout) :: data
            character(*), intent(in) :: string
            class(parent), intent(inout) :: this
        end subroutine

        module pure subroutine parent_proc2(this, string, DATA)
            class(parent), intent(in) :: this
            character(:), allocatable, intent(inout) :: string
            class(*), optional, intent(in) :: DATA
        end subroutine
    end interface

contains
    function default_parent() result(p)
        type(parent) :: p
        p = parent(name = 'default')
    end function
end module mod2

If I compile it, i get:

ifx -V -c /media/vmshare/implements-constructor.f90 
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2025.0.4 Build 20241205
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

 Intel(R) Fortran 25.0-1205.1
/media/vmshare/implements-constructor.f90(83): error #7316: Null components (probably caused by extra commas) in a structure constructor are invalid.   [CHILD]
        p = parent(name = 'default')
^

 

With flang-new (19.x), I get a similar error (that the constructor lacks a value for "ch"). But gfortran (14.x) compiles the code without issue.

 

As I see it, the child derived type already has full default initialization, so nothing should be required.

 

Am I correct or is the code invalid? 

0 Kudos
3 Replies
jwmwalrus
New Contributor I
755 Views

Sorry for bumping this, but...

 

@Ron_Green  or @Steve_Lionel Any thoughts on this?

0 Kudos
Ron_Green
Moderator
746 Views

@jwmwalrus  sorry for the delay.  I don't mind the bump.  I believe Steve is on vacation.  I will ask our Standards guru about this one.  It looks valid to me as well.  

Ron_Green
Moderator
709 Views

We think it's valid code.  And a bug in our compiler.  I have a bug report started, but I need to wait to submit it next week.  We have a number of our servers offline until Monday.  I need those up before I can finalize the report.  Once that is done I will have a bug ID to post here.

Reply