A subprogram declaration and subunit need not conform AI-00241/07 1 89-06-16 ra WA | !standard 06.03.01 (03) 89-06-16 AI-00241/07 !class ramification 88-01-19 | !status WG9-approved 89-06-16 !status ARG-approved (reviewed) 88-10-03 !status ARG-approved (13-0-0) 88-01-19 (pending editorial review) !status panel-approved (8-0-0) 87-09-15 (pending editorial review) !status ARG-approved (13-0-0) 87-09-14 (pending editorial review) !status panel/committee-approved (6-1-1) (10-2-2) 87-09-14 (by ballot) !status panel/committee-approved (7-0-2) 87-02-17 (pending letter ballot) !status work-item 87-01-16 !status received 84-05-03 !references 83-00356 | !topic A subprogram declaration and subunit need not conform !summary 88-08-15 Conformance is not a transitive relation. In particular, it is possible and legal to give a subprogram declaration that does not conform to the corresponding subunit specification (even though pairwise conformance is required between the declaration and body stub, and the body stub and the subunit). !question 87-03-13 6.3(3) says: If both a declaration and a body are given [for a subprogram], the subprogram specification of the body must conform to the subprogram specification of the declaration. When a subprogram body is given with both a body stub and a proper body, does this mean the declaration, body stub, and proper body must all conform? For example, consider: package P1 is type T is (ONE, TWO); end P1; with P1; package R is procedure Q (X : in out P1.T); -- 1 end R; package body R is use P1; package RENAMED renames P1; procedure Q (X : in out T) is separate; -- 2 end R; separate(R) procedure Q (X : in out RENAMED.T) is ... end Q; -- 3; legal? (yes) The specifications for Q at (1) and (2) conform, and those at (2) and (3) A subprogram declaration and subunit need not conform AI-00241/07 2 89-06-16 ra WA conform, but (1) does not conform with (3) (since RENAMED and P1 are not the same lexical elements (6.3.1(5))). Is the specification at (3) legal? !response 88-08-15 "Body" is a syntactic term that includes both body_stub and proper_body (see 3.9(2)); subunits are not included, and hence, are not bodies. Therefore, the quoted sentence from 6.3 does not apply to subunits -- although the specification in a subprogram declaration and the specification given in the corresponding body stub or proper body must conform, and similarly, the specification given in a body stub must conform to that given in the subunit (10.2(4)), there is no requirement that the specification in a subunit conform to the specification in a subprogram declaration. Hence the declaration at (3) is legal. Although this conclusion seems to be well-justified by the Standard, it is perhaps surprising that conformance is not a transitive relation. Can an interpretation or rule be found that would make conformance transitive? Some effort was spent in exploring this question, but it was not found possible to interpret or extend the rules to achieve this effect without changing the legality of programs. For example, the following rule was proposed: For purposes of the conformance rules, a simple name declared by a package renaming declaration can be replaced by another name for the same package. This rule was considered because non-transitive conformance is closely linked with the use of package names introduced by renaming declarations. However, this rule has the undesirable effect of changing the language in cases where transitivity is not an issue: package P is type T is (ONE,TWO); procedure Q_1(X : T); -- 1) package R is B : BOOLEAN := TRUE; end R; package RENAMED_R renames R; end P; subtype ST is P.T; package RENAMED_P renames P; procedure Q_2(X : P.T); -- 2) procedure Q_2(X : RENAMED_P.T) is ... end Q_2; -- 3) legal? procedure Q_3(X : BOOLEAN := P.R.B); -- 4) procedure Q_3(X : BOOLEAN := P.RENAMED_R.B) is ... end; -- 5) legal? A subprogram declaration and subunit need not conform AI-00241/07 3 89-06-16 ra WA package body P is procedure Q_1(X : ST) is ... end Q_1; -- 6) illegal end P; If the proposed rule were in effect: . The specifications of Q_1 at (1) and (6) would still not conform. . The specifications of Q_2 at (2) and (3) would now conform even though P.T and RENAMED_P.T do not conform under the existing rules. . Similarly, the specifications of Q_3 at (4) and (5) would now conform since RENAMED_R renames package R. Note that P.R would conform to P.RENAMED_R. In short, even if one thinks conformance was intended to be transitive, a rule like the proposed rule cannot be accepted because it would make the declarations at 3) and 5) legal. Such an effect cannot be justified simply to ensure transitive conformance between a subprogram declaration and its subunit. Consequently, it was decided that the proposed rule was inappropriate; it is better to accept the consequences of the current rules rather than to provide an interpretation that achieves more than just transitive conformance.