https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98022
--- Comment #7 from Steve Kargl <sgk at troutmask dot apl.washington.edu> --- On Sat, Dec 12, 2020 at 04:02:54PM +0000, pault at gcc dot gnu.org wrote: > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98022 > > --- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> --- > (In reply to kargl from comment #4) > > (In reply to Paul Thomas from comment #3) > > > > > function kn1() result(hm2) > > > complex :: hm(1:2), hm2(1:2) > > > data (hm(md)%re, md=1,2)/1.0, 2.0/ > > > hm2 = hm > > > end function kn1 > > > > Are you sure that this is valid Fortran? I cannot > > find anything in the Fortran standard that says hm%im > > is defined. Thus, 'hm2=hm' is referencing a variable > > that is no completely defined. > > > > > > 19.6.1 Definition of objects and subobjects > > > > 2 Arrays, including sections, and variables of derived, character, > > or complex type are objects that consist of zero or more subobjects. > > Associations may be established between variables and subobjects and > > between subobjects of different variables. These subobjects may become > > defined or undefined. > > > > 5 A complex or character scalar object is defined if and only if all > > of its subobjects are defined. > > Hi Steve, > > I saw your comment a bit too late. I think that you are correct. I guess that, > at very least, I should not zero out the undefined part of the complex object? > That way it would be equivalent to using assignment to achieve the same thing > or to partially define a derived type. > > I'll post on clf. > I recall looking at this PR a long time ago, but came up empty with ideas on how to fix it. You've some made some progress. It gets messy (at least to me) to determine if it is valid, and comes from reading 8.6.7 "Data statement", carefully. One gets to A data-stmt-constant other than boz-literal-constant, null-init, or initial-data-target shall be compatible with its corresponding variable according to the rules of intrinsic assignment (10.2.1.2). The variable is initially defined with the value specified by the data-stmt-constant; if necessary, the value is converted according to the rules of intrinsic assignment (10.2.1.3) to a value that agrees in type, type parameters, and shape with the variable. Now, we go to "what is a variable?" R902 variable is designator R901 designator is ... or complex-part-designator ... R915 complex-part-designator is designator % RE or designator % IM In your example, hm%re is real, so the rules for intrinsic assignment to a real applies. Of course, I could be wrong.