Hi,
The following code:
module meshgen_basic_common_m
type meshgen_options_t
integer:: x2d(4,2) = &
reshape ( [ 0, 1, 1, 0, &
0, 0, 1, 1 ], [4,2] )
end type meshgen_options_t
end module meshgen_basic_common_m
program t
use meshgen_basic_common_m
type(meshgen_options_t) :: po
po = meshgen_options_t()
end program t
gives with ifx compile
error #6595: The shape of a component in a structure constructor differs from the shape of the component of the derived type. [X2D]
po = meshgen_options_t()
^
compilation aborted for t.f90 (code 1)
Note, if I move the type definition from the module to the program the error message is gone.
I am using:
ifx (IFX) 2026.1.1 20260724
on Fedora Linux in WSL on Windows.
Martien
链接已复制
I think that your code is correct.
I had a look at the Fortran 2023 Standard (I only have a draft of the document). It says that if a component of a derived type ('meshgen_options_t') with default initialization (i.e. 'x2d' in your example) has no corresponding specification in the structure constructor, than the default initialization is applied to that component (see section 7.5.10 of the document).
I get the same error as you with both ifort (2021.10.0) and ifx (2026.1.0).
This seems to be due to the use of the 'reshape' function. For example, there is no problem with the following initialization:
integer :: x2d(4,2) = 0
Your code runs correctly when compiled with GNU Fortran 14.2.0.
To me this is probably a compiler bug.
I think there were a raft of bugs a "couple of years" back relating to functions defining constants in initialisation / parameter definition. Maybe this is another one. I think it relates to a standards relaxation in maybe f2018 or f2023.