J3/10-160 To: J3 From: Malcolm Cohen Subject: Final interp request 3. Date: 2010 June 01 ---------------------------------------------------------------------- NUMBER: TITLE: How does finalisation interact with allocatable assignment? KEYWORDS: Finalization DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider the program: Module m Type t1 Real c Contains Final :: f11 End Type Contains Subroutine f11(x) Type(t),Intent(InOut) :: x(:) Print *,'f11 called' End Subroutine End Module Program q Use m Type(t1),Parameter :: ap1(1) = [ t1(1.5) ] Type(t1),Parameter :: ap2(3) = [ t1(2.5),t1(3.5),t1(4.5) ] Type(t1),Parameter :: ap2(3) = t1(0.5) Type(t1),Allocatable :: x(:) x = ap1 ! (*1) x = ap2 ! (*2) x = ap3 ! (*3) End Program The topic is how 4.5.6.3 paragraphs 1 and 9 interact. The relevant texts are, respectively: "When an allocatable entity is deallocated, it is finalized." "When an intrinsic assignment statement is executed, the variable is finalized after evaluation of and before the definition of the variable." In the assignment marked (*1), paragraph 9 says that the variable (X) is finalized, i.e. CALL F11(X) is executed. However, this would be invalid, because an unallocated allocatable would be associated with a nonallocatable nonoptional dummy argument. In the assignment marked (*2), paragraph 9 again says that the variable is finalized - after evaluation of but before the definition of the variable. However, because the shapes of the variable and the expression differ, definition of the variable involves deallocating the variable (and allocating it with the correct shape). Paragraph 1 says that deallocating the variable finalizes it, so that means that F11 should be called twice for the variable. This is problematic since a finalized entity is not permitted to be referenced or defined by a final subroutine. In the assignment marked (*3), the variable and expression have the same shape so the variable will not be deallocated, so according to paragraph 9 it should be finalized once. Q1. Are all the assignment statements standard-conforming? Q2. How many times is the variable finalized (i.e. how many times is the final subroutine called) in each standard-conforming case? ANSWER: A1. Yes, all the assignment statements are intended to be standard conforming. Edits are supplied to correct the problem in (*1). A2. The variable is finalized exactly once, except when it was unallocated (and then it is not finalized). Edits are supplied to correct the problem in (*2). EDITS: {to 10-007} [76:17] In 4.5.6.3 When finalization occurs, paragraph 1, append to final sentence ", except when it is being deallocated during intrinsic assignment because the properties of the differ from those of the variable (7.2.1.3)". {Ugh - wordsmithing required here. 7.2.1.3 is "Interpretation of intrinsic assignments".} [76:32] In 4.5.6.3 When finalization occurs, paragraph 9, change "the variable" to "if the variable is not an unallocated allocatable variable, it", [76:33] append new sentence to paragraph: "If the variable was an allocated allocatable that is deallocated by intrinsic assignment, the finalization occurs before the deallocation of the variable.". SUBMITTED BY: Malcolm Cohen HISTORY: 10-nnn m192 Submitted ----------------------------------------------------------------------