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

Keyword initialization... again

John4
Valued Contributor I
519 Views

When I compile the code shown below, I get an error saying that "This is not a valid initialization expression". So, is keyword initialization valid for scalars but not for arrays?Also, is it allowed for PARAMETERs?

!--------------------------------------------------------------------------------------------------
module mod1

implicit none
private
save

type, public :: someType
character(63) :: attrib = ''
integer :: length = 255
integer :: dataType = 0
end type

type(someType) :: scalar = someType(attrib = 'so')
type(someType) :: array(1) = [ someType(attrib = 'something', length = 10) ]
! type(someType), parameter :: fixed = someType(attrib = 'fixed')

end module mod1
!--------------------------------------------------------------------------------------------------

0 Kudos
1 Solution
Steven_L_Intel1
Employee
519 Views
This problem was fixed in version 12.0 Update 1.

View solution in original post

0 Kudos
4 Replies
Steven_L_Intel1
Employee
519 Views
Keywords are not the problem here - for some reason that is not clear to me, the compiler doesn't like an array of derived type in an initialization expression. It should. In this particular case, you could get away with a scalar value here, but that would not work for a larger array. I will bring this to the developers' attention.
0 Kudos
John4
Valued Contributor I
519 Views

Arrays of derived type in an initialization expression don't seem to be the problem ---since the code below compiles just fine, although when the -stand option is given to the compiler, I get a warning (Overlapping storage initializations encountered with ARRAY ...)

Also, in regards to my second question: is there any restriction to creating PARAMETERs using keyword initialization (when the absent keywords are already initialized, of course)? If I uncomment the last module line in the code below, I get an error.

!--------------------------------------------------------------------------------------------------
module mod1

implicit none
private
save

type, public :: someType
character(63) :: attrib = ''
integer :: length = 255
integer :: dataType = 0
end type

type(someType) :: scalar = someType(attrib = 'so')
type(someType) :: array(1) = [ someType('something', 10, 0) ]
! type(someType), parameter :: fixed = someType(attrib = 'fixed')

end module mod1
!--------------------------------------------------------------------------------------------------

0 Kudos
Steven_L_Intel1
Employee
519 Views
Not really. The compiler is not behaving properly here. Issue ID is DPD200158135.
0 Kudos
Steven_L_Intel1
Employee
520 Views
This problem was fixed in version 12.0 Update 1.
0 Kudos
Reply