To: J3 J3/26-196r1 From: Brad Richardson & Generics Subject: Matching Deferred Procedure Interfaces Date: 2026-October-21 Reference: N2258-1, 26-190, 26-150r3 1. Background ============== 26-150r3 rewrote 16.5.4.4 to respond to UTI025, and in doing so made instantiation association of a deferred procedure considerably more flexible. Unfortunately it left open a problem. If the hypothetical deferred procedure as wrapper is taken literally, it would imply that extra defined assignment or final subroutines would be invoked. This is not intended. As an example, consider the following module defining a derived type with a final subroutine, a template instantiated with it and a program that calls the instantiated procedure. MODULE EXAMPLE TYPE :: MY_T CONTAINS FINAL :: FINAL_MY_T END TYPE TEMPLATE TMPL{T, S} DEFERRED TYPE :: T DEFERRED INTERFACE SUBROUTINE S(X) TYPE(T), INTENT(OUT) :: X END SUBROUTINE END INTERFACE CONTAINS SUBROUTINE CALL_IT(X) TYPE(T), INTENT(INOUT) :: X CALL S(X) END SUBROUTINE END TEMPLATE INSTANTIATE TMPL{MY_T, DO_NOTHING} CONTAINS SUBROUTINE FINAL_MY_T(SELF) TYPE(MY_T), INTENT(INOUT) :: SELF PRINT *, "FINAL_MY_T called" END SUBROUTINE SUBROUTINE DO_NOTHING(X) TYPE(MY_T), INTENT(OUT) :: X END SUBROUTINE END MODULE PROGRAM DEMO USE EXAMPLE TYPE(MY_T) :: X CALL CALL_IT(X) END PROGRAM If in the above example the deferred procedure as a wrapper is taken literally, that means that FINAL_MY_T should be called twice - once for the call to the deferred procedure, and once for the call to the instantiation argument. We don't want this to be the case. We want the call to S to be considered to be a call to the instantiation argument, not a call to some wrapper procedure. 2. Design ========= The fix keeps the hypothetical reference - it is still the simplest way to state the argument-correspondence requirements (INTENT, and, via ordinary argument-association rules, the trailing-optional and assumed-rank flexibility that NOTE 2 describes) and to say what generic resolution is performed against - but says up front what it is for: determining argument correspondence and, where applicable, performing generic resolution. This makes it clearer that a reference to the deferred procedure is simply a reference to the procedure identified as its instantiation argument, with the same actual arguments, and this does not entail any additional procedure reference, intermediate result object, defined assignment, or invocation of a final subroutine beyond what that direct reference entails. We had also missed some rules about PURE and SIMPLE which this new paragraph addresses. 3. Edits ======== In Subclause 16.5.4.4 Instantiation association of a deferred procedure [406:8-18] Replace the paragraph with the following. "The following is determined as if there were a procedure reference to an instantiation argument corresponding to a deferred procedure where the actual arguments provided are the dummy arguments of the deferred procedure in order. If the instantiation argument is not a generic-spec, that reference shall be valid and the instantiation argument is the deferred procedure's corresponding procedure. If the instantiation argument is a generic-spec, generic resolution is performed by that reference, and the selected specific procedure is the deferred procedure's corresponding procedure. If the INTENT of a dummy argument of the deferred procedure is: * IN, the corresponding dummy argument of the corresponding procedure shall be INTENT(IN); * INOUT, the corresponding dummy argument of the corresponding procedure shall be INTENT(INOUT) or INTENT(OUT); * OUT, the corresponding dummy argument of the corresponding procedure shall be INTENT(OUT); * unspecified, the corresponding dummy argument of the corresponding procedure may have any INTENT. If the deferred procedure is PURE, the corresponding procedure shall be PURE. If the deferred procedure is SIMPLE, the corresponding procedure shall be SIMPLE. Upon instantiation, references to the deferred procedure are references to the corresponding procedure." [406:18+] Delete Note 1 in its entirety {just some realignment of the terms in following constraints} [406:19] Change "instantiation procedure" to "instantiation argument" [406:23] Change "corresponding instantiation argument" to "corresponding procedure" [406:25] Change "instantiation argument" to "corresponding procedure" --END--