J3/10-159 To: J3 From: Malcolm Cohen Subject: Final interp request 2. Date: 2010 June 01 Note: Depending on the answer to final interp request 1, this one might be irrelevant. ---------------------------------------------------------------------- NUMBER: TITLE: Are constants finalized? KEYWORDS: Finalization DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider the program: Module m Type t1 Real c Contains Final :: f10,f11 End Type Type,Extends(t0) :: t2 Real d Contains Final :: f20,f21 End Type Contains Subroutine f10(x) Type(t),Intent(InOut) :: x Print *,'f10 called' End Subroutine Subroutine f11(x) Type(t),Intent(InOut) :: x(:) Print *,'f11 called' End Subroutine Subroutine f20(x) Type(t),Intent(InOut) :: x Print *,'f20 called' End Subroutine Subroutine f21(x) Type(t),Intent(InOut) :: x(:) Print *,'f21 called' End Subroutine End Module Program q Use m Type(t1),Parameter :: p1 = t1(1.5) Type(t2),Parameter :: p2 = t2(2.5,-3.5) Type(t1),Parameter :: ap1 = [ p1 ] Type(t2),Parameter :: ap2 = [ p2 ] Call sub1(p1) Call sub1(t1(1.5)) ! (*) Call sub2(p2) Call sub2(t2(2.5,-3.5)) ! (*) Call sub1a(ap1) Call sub1a([p1]) ! (*) Call sub2a(ap2) Call sub2a([p2]) ! (*) End Program The topic is how many times each final procedure is called on return from each subroutine? Clearly, the final procedures are not called on return from the calls not marked with an asterisk. For the ones marked with an asterisk, the situation is less clear. The standard says that a structure constructor or array constructor is finalized "[if] an executable construct references [it]" (4.5.6.3p5). However, the term "reference" is not defined for these entities; the closest would seem to be "appearance of a data object designator in a context requiring its value at that point during execution" which would appear on the face of it to mean that these entities are finalized since the constructor appears in a context requiring its value. Possible interpretations might be (a) Yes, the entities are required to be finalized (so the relevant final procedure is executed). (b) The text in 4.5.6.3p5 was not intended to be applied to constants (the standard is defective). (c) The processor can optionally evaluate an alternative expression with the same value, viz an named constant, so it is processor dependent whether the finalizer is called. Option (a) seems inconsistent with named constants otherwise being equivalent to their constant expression. Option (c) argument could be equally applied to nonconstant constructors, so this would make all finalization of constructed values optional. That would seem inconsistent with the purpose of finalization. Which is the correct approach? ANSWER: The quoted text was not meant to be applied to constants. An edit is supplied. EDITS: {to 10-007} [76:24] In 4.5.6.3 When finalization occurs, paragraph 6, Before ", the entity created" insert ", and the constructor is not a constant expression (7.1.12)". {Note avoiding the BNF syntax term as that would be incorrect.} SUBMITTED BY: Malcolm Cohen HISTORY: 10-nnn m192 Submitted ----------------------------------------------------------------------