[flang] Accept structure constructors omitting a component whose type has default initialization (#247370)
flang rejected a structure constructor that omits a non-pointer,
non-allocatable component of derived type.
This rejection is when the component has no initializer of
its own but its type has default initialization.
Here is an example:
type inner
integer :: x = 1
end type
type outer
type(inner) :: comp
end type
type(outer) :: v
v = outer() ! error: Structure constructor lacks a value for component
'comp'
According to the Fortran Standard, a component as shown in the above
example has default initialization (F'2023 7.5.4.6 p8), so it may
be omitted (C7104) and its default initialization applies (7.5.10 p3).
CheckStructureConstructor is changed so that it now builds the omitted
component's value as a nested structure constructor. This nested
structure constructor value is from its type's default
initialization. The value is built in semantics because constant
lowering uses only the constructor's explicit values.
A component is still reported as missing
when its type has no default initialization, for example when its
only subcomponents are allocatable components or pointers without
an initializer.
Omitting a component is still an error when a nonpointer, nonallocatable
subcomponent of its type has no default value.
Assisted-by: AI