(j3.2006) Intrinsic assignment of derived types
Clune, Thomas L. GSFC-6101
thomas.l.clune
Sat Feb 3 20:03:47 EST 2018
I do not think that the example is standard conforming. (And I certainly _hope_ it is not standard conforming.)
In the statement
foo = bar
the expr is of type e not t. It does not matter that the variable ?bar? is of declared type t.
On Feb 3, 2018, at 5:45 PM, Steve Lionel <steve at stevelionel.com<mailto:steve at stevelionel.com>> wrote:
Consider:
type :: t
end type
type, extends(t) :: e
end type
type(t) :: foo
class(t), allocatable :: bar
allocate( e :: bar )
foo = bar
end
Is the assignment of bar to foo valid, and if so, what does it do? Referencing 18-007, 10.2.1.2 requires that the type of the expr be "the same derived type as the variable". Here they are of the same declared type, but not the same dynamic type.
Then in 10.2.1.3p13, it says, "An intrinsic assignment where the variable is of derived type is performed as if each component of the variable
were assigned from the corresponding component of expr..." One could interpret this as copying only the components of bar that are in foo. One compiler I have access to allows this, another does not, complaining that the types don't match.
What exactly does "same derived type" mean here? Would it be correct/useful to change the words in table 10.8 to say "same dynamic type"?
Steve
_______________________________________________
J3 mailing list
J3 at mailman.j3-fortran.org<mailto:J3 at mailman.j3-fortran.org>
http://mailman.j3-fortran.org/mailman/listinfo/j3
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.j3-fortran.org/pipermail/j3/attachments/20180204/659ac138/attachment.html>
More information about the J3
mailing list