To: J3 J3/25-140 From: generics Subject: Miscellaneous edits to incorporate templates Date: 2025-May-19 References: 25-112, 25-135, 25-136, 25-137, 25-138, 25-139, 24-125r5, 24-126r4, 24-127r4 1. Introduction =============== This is the 6th of 6 papers that provide edits for the approved syntax for templates. This paper describes various edits occurring outside the new new clause introduced in papers 1-5 that are necessary to incorporate the syntax and semantics for templates. 2. Edits required for deferred arguments ======================================== * Insert new glossary term in 3.7 [deferred argument association] association between an instantiation argument and a deferred argument (Sec. ?) * Insert new glossary term [deferred argument] named entity that appears in a (R???) (Sec. ?) * Insert new glossary term 3.34.x [deferred constant] a deferred argument with the PARAMETER attribute * Insert new glossary term [instantiation argument] entity that determines deferred argument association * Insert new glossary term [ultimately defined prior] {could shorten to "defined prior" but that might be too confusing compared to "previously defined"} "an entity that is accessed by host association and whose definition appears before the scoping unit in which it is reference or is ultimately defined prior in the host scoping unit" * 3.120 Add TEMPLATE construct and REQUIREMENT construct to the list in the definition so that it now reads: "BLOCK construct, derived-type definition, interface body, program unit (3.113), subprogram, template construct, or requirement construct, excluding all nested scoping units in it" * 3.139 Modify subprogram to include templated functions and subroutines to read: " (R1532), (R1537), (R???), or (R???)" * 5.4.1.1 General Modify first sentence of paragraph 2 to read: "A type is either an intrinsic type, a derived type, or a deferred type." * 5.4.1.3 Derived type Add new subclause "5.4.1.3+ Deferred type Deferred types are deferred arguments that are types in templates, templated procedures, or requirements. Deferred types are described further in tt.xx. " * 7.3.2.1 Type specifier syntax Extend R702 to include such that it reads: " R702 <> <> <> <> <> " Modify C703 to include such that it reads: "(R702) The or shall not specify an abstract type (7.5.7) except when it appears as an ." Extend R703 to include such that it reads: "R703 <> <> TYPE ( ) <> TYPE ( ) <> TYPE ( ) <> TYPE ( ) <> TYPE ( ) <> CLASS ( ) <> CLASS ( ) <> CLASS ( * ) <> TYPE ( * ) <> TYPEOF ( ) <> CLASSOF ( )" Change C705 wording to be consintent with constraints just after it: "C705 (R703) CLASS() shall specify an extensible type (7.5.7)." {This is just a wording change, but the original is so glaringly different than the nigh identical constraint that follows, that generics subgroup thought it should be updated.} After C705 introduce a new constraint: "C705+ (R703) CLASS() shall specify an extensible type (7.5.7)." After C706 introduce a new constraint "C706+ (R703) TYPE() shall not specify an abstract type (7.5.7)." * 7.5.2.1 Syntax of a derived-type definition Insert new constraint on R728: "C737b (R728) shall not be a ." * 8.5.2 Accessibility attribute In C817, insert "or template" after "module", so that it now reads: "C817 An access-spec shall appear only in the specification-part of a module or template construct." * 8.6.1 Accessibility Statement Change C873 to allow for templates: "C873 (R831) An shall appear only in the of a module or template. Only one accessibility statement with an omitted is permitted in the of a module or template." Change C874 to allow for templates: "C874 (R831) Each shall be the name of a module, variable, procedure, nonintrinsic type, named constant other than a deferred constant, namelist group, requirement, or template." In 2nd sentence of paragraph 1, insert "or template" after "in the module" in both locations such that the sentence now reads: "An access-stmt without an access-id list specifies the default accessibility of the identifiers of entities declared in the module or template, and of entities accessed from a module whose name does not appear in any access-stmt in the module or template." In last sentence of paragraph 1, insert "or template" after "in a module" such that the sentence now reads: "If no such statement appears in a module or template, the default is public accessibility." In 1st sentence of paragraph 2, insert "or template" after "in the module" such that the sentence now reads: "If an identifier is accessed by use association and not declared in the module or template, and the name of every module from which it is accessed appears in an access-stmt in the scoping unit, its default accessibility is PRIVATE if the access-spec in every such access-stmt is PRIVATE, or PUBLIC if the access-spec in any such access-stmt is PUBLIC." * 8.5.8.1 General Change last entry for from: "<> " To: "<> " * 8.5.8.2 Explicit-shape array Modify R818 to disambiguate lower and upper explicit bounds such that it reads: "R818 <> [ : ] <> : <> : R818b <> R818c <> " * 8.5.8.6 Implied-shape array Modify the first sentence from: "An implied-shape array is a named constant that takes its shape from the constant-expr in its declaration." To: "An implied-shape array is a named constant that takes its shape from a constant expression. If it is a deferred constant, it takes its shape from the associated instantiation argument, otherwise it takes its shape from the constant expression in its declaration." {Note that this change is a bit larger than strictly necessary. It is needed for deferred constants, but it seems natural to include ordinary constant here.} Delete the first sentence in the last paragraph which reads: The extent of each dimension of an implied-shape array is the same as the extent of the corresponding dimension of the constant-expr. * 8.5.8.7 Assumed-rank entity Change name of section to "Assumed-rank or implied-rank entities" Modify text in former 8.5.8.7 (Assumed-rank entity) to use new syntax term such that it now reads: "An assumed-rank entity is a dummy data object whose rank is assumed from its effective argument, or the associate name of a RANK DEFAULT block in a SELECT RANK construct; this rank can be zero. The bounds and shape of an assumed-rank entity with the ALLOCATABLE or POINTER attribute are determined as specified in 8.5.8.4. An assumed-rank entity is declared with an that is an . R827 assumed-or-implied-rank-spec is .. C839 An assumed-rank entity shall be an associate name or a dummy data object that does not have the CODIMENSION or VALUE attribute. C840 An assumed-rank variable name shall not appear in a designator or expression except as an actual argument that corresponds to a dummy argument that is assumed-rank, the argument of the function C_LOC or C_SIZEOF from the intrinsic module ISO_C_BINDING (18.2), the first dummy argument of an intrinsic inquiry function, or the selector of a SELECT RANK statement. C841 If an assumed-size or nonallocatable nonpointer assumed-rank array is an actual argument that corresponds to a dummy argument that is an INTENT (OUT) assumed-rank array, it shall not be polymorphic, finalizable, of a type with an allocatable ultimate component, or of a type for which default initialization is specified. * Insert new section after 8.5.8.7.1: "8.5.8.7.2 Implied-rank entity An implied-rank entity is an entity whose rank becomes defined only within the instantiation of a template. The following are implied-rank entities: - deferred constant declared with - variable, dummy argument, or deferred constant whose rank is declared to be a deferred integer, scalar constant expression - variable, dummy argument, or deferred constant whose shape is declared to be a deferred integer, rank-1 array expression. {UTI: Also make sure it works with SELECT GENERIC RANK and spell out what can be done with implied-rank entities. Contingent on edits for auto-generic procedures.} NOTE The following are examples of implied-rank entities TEMPLATE EXAMPLE(C, S, N) DEFERRED INTEGER, PARAMETER :: S(*) DEFERRED INTEGER, PARAMETER :: C(..) ! implied-rank INTEGER, PARAMETER :: B(S) = 1 ! implied-rank REAL, PARAMETER, RANK(RANK(C)) :: D ! implied rank END TEMPLATE * 8.5.17 RANK clause {UTI: Do we want to allow RANK(*)? Not strictly necessary given that we have DIMENSION(..). Low priority.} Replace constraint C864 which states: C864 An entity declared with a rank-clause shall be a dummy data object or have the ALLOCATABLE or POINTER attribute. With: C864 An entity declared with a rank-clause shall be a named constant, dummy data object or have the ALLOCATABLE or POINTER attribute. {This change is a bit larger than strictly necessary for generic programming. We only need to allow it for deferred constants, but it seems natural to allow for ordinary named constants as well.} Amend the last sentence of the section to allow for the deferred constant case, such that the paragraph now reads: "If the rank is zero the entity is scalar; otherwise, if it has the ALLOCATABLE or POINTER attribute, it specifies that it is a deferred-shape array; otherwise, if it is a named constant, it specifies that it is an implied-shape array with all lower bounds equal to one; otherwise, it specifies that it is an assumed-shape array with all the lower bounds equal to one". * 8.6.1 Accessibility statement Modify C873 to include templates such that it reads: "C873 An shall appear only in the of a module or template construct. Only one accessibility statement with an omitted is permitted in the of a module or template construct." * 10.1.12 Constant expression Extend list in normative text for "constant expression" to include "deferred constant" {UTI: The following section was well intended but cast too large of a shadow. We should elsewhere specify similar sentiments but restricted to RANK and KIND with regards to TKR resolution.} * Insert new section 10.1.12+: Deferred constant expressions " <> An expression is a if one or more of its primaries is a deferred constant. A is not equal to any other unless is syntactically equivalent." deferred integer, parameter :: C deferred integer, parameter :: R integer, parameter :: R2 = C real, rank(R), allocatable :: x select rank (x) rank is (0) rank is (1) rank is (2) rank is (3) ... end select rank real, rank(C), allocatable :: y real, rank(R2), allocatable :: z if (rank(x) == rank(y)) then ... end if if (rank(z) == rank(y)) then ... end if template tmpl(C) * 11.1.11.1 Purpose and form of the SELECT TYPE construct Extend R1156 to include , such that it now reads: "R1156 <> TYPE IS ( ) [ ] <> CLASS IS ( ) [ ] <> CLASS IS ( ) [ ] <> CLASS DEFAULT [ ]" Add constraint to R1156: C1169b (R1156) shall specify an extensible type. * 15.5.1 Syntax of a procedure reference {UTI: spelling of vs } Extend R1522 with and such that it reads: "R1522 <> <> <> % binding-name <> <> Extend R1524 with and such that it reads: "R1524 actual-arg <> <> <> <> <> <> <> <> {UTI - the section distinction between 2 & 3 here are probably fiction at this point.} 3. Edits required for templates and instantiation ================================================= * 5.1 High level syntax Extend R508 to include new syntax terms: