12-174 To: J3 From: Tobias Burnus, revised by Van Snyder Subject: Pointer arguments to PURE functions Date: 2012 October 05 References: WG5/N1830 Pre-remark: The issue was found by Ian Harvey at comp.lang.fortran. The change was done from 08-007r2 to 09-007 (in C1280); the change was proposed in 08-181 and is listed in the editor's report 09-102. ---------------------------------------------------------------------- NUMBER: TBD TITLE: Pointer arguments to PURE functions KEYWORDS: PURE function, pointer, intent(in) DEFECT TYPE: TBD STATUS: TDB QUESTION: Fortran 2003 prohibited the modification of the arguments to pure functions via C1272 In a pure subprogram any designator with a base object that is in common or accessed by host or use association, is a dummy argument of a pure function, is a dummy argument with INTENT (IN) of a pure subroutine, or an object that is storage associated with any such variable, shall not be used in the following contexts: [...] In Fortran 2008, the constraint was modified to: C1283 In a pure subprogram any designator with a base object that is in common or accessed by host or use association, is a dummy argument with the INTENT (IN) attribute, is a coindexed object, or an object that is storage associated with any such variable, shall not be used [...] (1) Is the following procedure standard conforming and, if so, was it intended to be standard conforming? pure function F( X ) real, pointer :: X real :: F f = 1.0 x = 2.0 end function F (2) Is the following procedure standard conforming and, if so, was it intended to be standard conforming? pure function G ( X ) real, pointer :: X real :: G g = 1.0 nullify ( x ) end function G ANSWER: Both functions are standard conforming, but were not intended to be. It was intended that pure functions do not have side effects. In Fortran 2003, C1272 prohibited assigning a value to the target of X, and prohibited changing the association status of X, by way of the definition of "variable definition context." It was an oversight to remove "is a dummy argument of a pure function" from Fortran 2008. Edits are provided to repair this defect. EDITS: [1.6.1+ 12-007:24:7+] Insert a subclause: "1.6.1a Fortran 2008 compatibility Except as identified in this subclause, this part of ISO/IEC 1539 is an upward compatible extension of ISO/IEC 1539-1:2010. With the following exceptions, any standard-conforming Fortran 2008 program remains standard-conforming under this part of ISO/IEC 1539. o Fortran 2008 allowed a pure function to cause a side effect by assigning a value to the target of a pointer dummy argument, or by changing its association status. This is now prohibited." [12.7 C1283 12-007:312:31] Insert ", is a dummy argument of a pure function" after "association". REMARK: It would not be feasible to require that pointer dummy arguments of pure functions have the INTENT(IN) attribute, as this would be a significant departure from compatibility with Fortran 2003 and Fortran 2008. SUBMITTED BY: Tobias Burnus HISTORY: 12-xxx m199 F08/xxxx submitted ----------------------------------------------------------------------