J3/15-179r1 To: J3 From: Malcolm Cohen Subject: Interp on statement functions returning PDTs Date: 2015 August 05 ---------------------------------------------------------------------- NUMBER: F08/0141 TITLE: Can a statement function have a variable-length PDT result? KEYWORDS: Statement function, parameterized derived type DEFECT TYPE: Erratum STATUS: J3 consideration in progress QUESTION: Consider MODULE m207c006 TYPE string(n) INTEGER,LEN :: n CHARACTER(n) :: v END TYPE END MODULE PROGRAM test USE m207c006 CALL s(3) CALL s(7) CONTAINS SUBROUTINE s(n) TYPE(string(n)) sf TYPE(string(n)) var(3) sf(nn) = var(nn) var(1) = string(n)('123456789') var(2) = string(n)('abcdefgh') PRINT *,sf(1),sf(2) END SUBROUTINE END PROGRAM If this is conforming, it would appear that the output ought to be 123abc 1234567abcdefg However, for the following reasons, perhaps this is not intended to be conforming. (1) A statement function of type character is required to have a constant length type parameter. There is no such requirement on a statement function of parameterized derived type. This seems inconsistent, since one can wrap a variable-length character in a parameterized derived type. (2) A statement function is not permitted to invoke a nonintrinsic function that requires an explicit interface (and having a PDT result requires an explicit interface), nor is it permitted to contain a structure constructor. This would seem to render such a statement function almost completely useless, since all it can do is to choose between PDT constants or variables, or use an intrinsic function such as TRANSFER to construct the result. (3) Statement functions were declared to be obsolescent long before the addition of parameterized derived types to the standard. It has been general policy not to "improve" obsolescent features. This would seem to indicate that statement functions were not intended to be capable of having parameterized derived type in the first place. Q1. Are statement functions of parameterized derived type intended to be conforming? Q2. If so, are statement functions of parameterized derived type with nonconstant length type parameters intended to be conforming? Q3. If so, is the expected output from the example program above as described? ANSWER: A1. No, statement functions were not intended to be permitted to be of parameterized derived type. The exception for statement functions from the explicit interface requirements was overlooked. An edit is provided to prohibit these. A2, A3. Moot. EDITS: [22:11+] 1.6.2 Fortran 2003 compatibility, insert new paragraph "Fortran 2003 permitted a statement function to be of parameterized derived type; this part of ISO/IEC 1539-1 does not permit that." {Previous corrigenda have already inserted incompatibility paragraphs.} [311:34+] 12.6.4 Statement function, after C1275, insert constraint "C1275a A statement function shall not be of a parameterized derived type." SUBMITTED BY: Malcolm Cohen HISTORY: 15-179 m207 F08/0141 Submitted 15-179r1 m207 Revised edits. ----------------------------------------------------------------------