To: J3 J3/23-236r1 From: Tom Clune Subject: Templates in CONTAINS section Date: 2023-October-18 Reference: 23-155r2 1. Introduction =============== One awkwardness of the proposed syntax for templates is that template procedures appear before the CONTAINS section within a host module. The awkwardness is compounded in the case of nested templates which then have the procedures of inner templates appear before the CONTAINS section of the outer template. Recently generics subgroup considered the possibility of altering the proposed syntax to have template definitions appear in the CONTAINS section of their hosting scope rather than in the specification section as is the case now. MODULE A INSTANTIATE T(REAL) CONTAINS TEMPLATE OUTER(T) TYPE, DEFERRED :: T INSTANTIATE INNER(N=1) CONTAINS TEMPLATE INNER(N) INTEGER, CONSTANT :: N CONTAINS SUBROUTINE S(x) TYPE(T), RANK(N), INTENT(INOUT) :: x ... END SUBROUTINE S END TEMPLATE INNER SUBROUTINE G(x) TYPE(T), INTENT(INOUT) :: x TYPE(T) :: y(1) y = SPREAD(x, 1) CALL S(y) ... END SUBROUTINE G END TEMPLATE OUTER END MODULE A Subgroup was weakly in favor of this change, but would prefer to solicit the opinion of others before introducing such a change. 2. Straw vote ============= Should template syntax be modified to place template definitions in the CONTAINS section rather than the specification of the hosting scope? Yes: TEMPLATES should be defined in the CONTAINS section of the encompassing scope. Appropriate changes will be made to generics syntax. No: TEMPLATES should be defined in the specification section of the encompassing scope. No change to generics syntax. Abstain: ===END===