J3/10-182 To: J3 From: Malcolm Cohen Subject: Final interp 6: PURE FUNCTION results Date: 2010 June 13 ---------------------------------------------------------------------- NUMBER: TITLE: PURE FUNCTION result finalization KEYWORDS: PURE FUNCTION FINAL DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider MODULE m TYPE t REAL c CONTAINS FINAL f END TYPE INTEGER :: fcount = 0 CONTAINS SUBROUTINE f(x) TYPE(t),INTENT(INOUT) :: x x%c = 0 fcount = fcount + 1 END SUBROUTINE PURE TYPE(t) FUNCTION f(a) REAL,INTENT(IN) :: a f%c = a END FUNCTION END MODULE Even though this function is PURE, invoking it will inevitably result in the execution of the impure FINAL subroutine f. Thus, it presumably cannot be used in any context requiring purity. Some other cases of impure finalization are prohibited by C1284, but not this because it does not occur "in" the procedure. Should an impurely-finalizable function result be allowed for a pure function? ANSWER: No, this should not be allowed. An edit is supplied to correct this oversight in the requirements for pure procedures. EDITS to 10-007: [312:20+] In 12.7 after C1276, insert new constraint "C1276a The result variable of a pure function shall not be of a type, kind parameters, and rank that would result in the execution of an impure procedure when the result of a reference to the function is finalized." ALTERNATIVE: "C1276a The result variable of a pure function shall not be such that finalization of a reference to the function would reference an impure procedure." SUBMITTED BY: Malcolm Cohen HISTORY: 10-182 m192 Submitted ----------------------------------------------------------------------