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

explicit initialization of derived type parameters; positional vs keyword fields

joseph_battelle
Beginner
1,967 Views
It seems that the current compiler only allows positional fields inside structure constructors when initializing parameters. Variable derived types can be explicitly initialized by structure constructors with named fields as well as positional. See code below for examples. Is this a bug or is this what the standard requires? I haven't found it in the standard (yet).
Compiling with Intel Visual Fortran 11.1.065 [IA-32]...
[fortran]program C4

    type :: m
        integer :: i = 0
    end type

    type :: o
        integer :: id = 0
        type(m) :: cache = m (1)
        logical :: multi = .false.
    end type o

    !OK
    type(o)            :: x1 = o(1, multi=.true., cache = m(5))
    type(o)            :: x2 = o(1, cache=m(5), multi=.true.)
    type(o)            :: x3 = o(1, cache=m(5))
    type(o)            :: x4 = o(1, multi=.true.)
    !error #7747: Invalid parameter expression.   
    type(o), parameter :: a1 = o(1, multi=.true., cache = m(5))
    !error #7747: Invalid parameter expression.   
    type(o), parameter :: a2 = o(1, multi=.true.)
    !OK relying on default initializers as long as you dont name fields
    type(o), parameter :: a4 = o(1, m())
    !error #7747: Invalid parameter expression.      
    type(o), parameter :: a3 = o(1, cache=m())
    
end program C4[/fortran]

0 Kudos
1 Solution
Steven_L_Intel1
Employee
1,967 Views
Escalated as issue DPD200157285. Thanks for the nice example.

View solution in original post

0 Kudos
6 Replies
Steven_L_Intel1
Employee
1,968 Views
I know we've had some issues with keywords in structure constructors - I'll take a look at this on Monday.
0 Kudos
joseph_battelle
Beginner
1,968 Views
Thanks for looking into this Steve. The standard talks of only one sort of structure constructor and my reading is that all of the above code should be valid.
-joe
0 Kudos
joseph_battelle
Beginner
1,968 Views
Any progress on characterizing this?
0 Kudos
Steven_L_Intel1
Employee
1,968 Views
Not yet -sorry. But I will get to it soon.
0 Kudos
Steven_L_Intel1
Employee
1,968 Views
Escalated as issue DPD200157285. Thanks for the nice example.
0 Kudos
Steven_L_Intel1
Employee
1,968 Views
This will be fixed in an update, probably the first one, to the next major release.
0 Kudos
Reply