J3/15-179 To: J3 From: Malcolm Cohen Subject: Interp on statement functions returning PDTs Date: 2015 June 16 ---------------------------------------------------------------------- NUMBER: F08/0141 TITLE: Can a statement function have a nonconstant type parameter? 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. ALTERNATIVE ANSWER: A1. Yes, statement functions are intentionally permitted to be of parameterized derived type. A2. No, statement functions were not intended to be permitted to have a nonconstant length type parameter. An edit is provided to prohibit this. A3. Moot. EDITS: [311:34+] 12.6.4 Statement function, after C1275, insert constraint "C1275a A statement function shall not be of a parameterized derived type." ALTERNATIVE EDITS: Left as an exercise for the reader. SUBMITTED BY: Malcolm Cohen HISTORY: 15-nnn m207 F08/0141 Submitted ----------------------------------------------------------------------