J3/11-194 To: J3 From: Malcolm Cohen Subject: Multiple choice non-polymorphic allocation interp. Date: 2011 June 13 ---------------------------------------------------------------------- NUMBER: TITLE: Non-polymorphic ALLOCATE with polymorphic SOURCE= KEYWORDS: ALLOCATE, polymorphic, SOURCE=. DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider Program m195_m1 Type t Real c End Type Type,Extends(t) :: t2 Real d End Type Class(t),Allocatable :: x Type(t),Allocatable :: y Allocate(x,Source=t2(1.5,-1.5)) Allocate(y,Source=x) ! (*) ... End Program Is the second ALLOCATE statement (marked *) standard-conforming? The only requirement is that Y be type-compatible with X; they both have the same declared type so this is true. However, the very similar Allocate(y,Source=t2(1.2,-1.5)) would not be conforming because Y is not type-compatible with the structure constructor, and y = x would also also not conforming (the dynamic types being different). However, the standard says that "the value of [y] becomes that of [x]" which is clearly impossible. Since the standard fails to establish an interpretation one might conclude that the example is not conforming. However, the similar situation with the dynamic types being the same but with non-deferred length type parameters being different is explicitly stated to be conforming (and to raise an error condition), perhaps this was also intended to raise an error condition. It is also possible that the intent was to use the value of the declared type part in this case, as happens for pointer assignment. What is the interpretation of this ALLOCATE statement? ANSWER 1: The statement was intended to be conforming and to use the declared type part of the source-expr only. An edit is supplied to clarify. ANSWER 2: The statement was intended to be conforming and to cause an error condition at runtime if the dynamic types were different: an edit is supplied to clarify. ANSWER 3: The statement was not intended to be conforming. An edit is supplied to clarify. EDIT 1: [128:24] In 6.7.1.2p7, before "On successful", insert "If an is not polymorphic and the is polymorphic with a dynamic type that differs from its declared type, the value provided for that is the ancestor component of the that has the type of the ; otherwise, the value provided is the value of the ." [128:25-26] Replace "that of " with "the value provided", twice. EDIT 2: [128:24] In 6.7.1.2p7, before "On successful", insert "If an is not polymorphic and the is polymorphic with a dynamic type that differs from its declared type, an error condition occurs." EDIT 3: [128:24] In 6.7.1.2p7, before "On successful", insert "If an is not polymorphic, the dynamic type of the shall not differ from its declared type." SUBMITTED BY: Malcolm Cohen HISTORY: 11-nnn m195 Submitted ----------------------------------------------------------------------