Version 1.1 of ai05s/ai05-0222-1.txt
!standard 3.9.2(13) 10-10-20 AI05-0222-1/01
!standard 13.14(16)
!class binding interpretation 10-10-20
!status work item 10-10-20
!status received 10-03-25
!priority Low
!difficulty Easy
!qualifier Error
!subject A completion of a primitive subprogram can occur after freezing
!summary
A completion of a primitive subprogram of a tagged type can occur after the
freezing of the tagged type.
!question
Consider:
package Pak1 is
type T1 is tagged record ... end record;
procedure Op (X : in out T1);
end Pak1;
with Pak1;
procedure Proc2 is
type T2 is new Pak1.T1 with record ... end record;
overriding
procedure Op (X : in out T2);
Var : T2;
overriding
procedure Op (X : in out T2) is --
begin
...
end Op;
...
3.9.2(13): "The explicit declaration of a primitive subprogram of a
tagged type shall occur before the type is frozen."
6.3(5): "A subprogram_body is considered a declaration. It can either
complete a previous declaration, or itself be the initial declaration
of the subprogram."
one could think that since line (A) is a declaration, it's overriding
a primitive subprogram, and it's occurring after the type is frozen,
that 3.9.2(13) makes it illegal.
That clearly makes no sense; should this be fixed? (Yes.)
!wording
Modify 3.9.2(13):
The explicit declaration {that is not a completion} of a primitive
subprogram of a tagged type shall occur before the type is frozen (see 13.14).
For example, new dispatching operations cannot be added after objects or
values of the type exist, nor after deriving a record extension from it, nor
after a body.
Modify 13.14(16):
The explicit declaration {that is not a completion} of a primitive
subprogram of a tagged type shall occur before the type is frozen (see 3.9.2).
!discussion
The example in the question is a pathology.
Subprograms in a package body are not primitive, but may complete a primitive
subprogram, so it is arguable if these rules apply to them (clearly, they were
not intended to).
But the introduction of expression functions by AI05-0177-1 makes this a more
significant problem. We would not want the following to be illegal:
package Pak2 is
type T is tagged private;
function F (Obj : T) return Boolean;
private
type T is tagged record
Flag : Boolean;
end record;
Object : T; --
function F (Obj : T) return Boolean is (Obj.Flag);
end Pak2;
So we need to fix this.
!ACATS Test
An ACATS test could be constructed for the expression function case (the
example of the question is too much of a pathology to matter).
!appendix
!topic Subprogram body declarations and 3.9.2(13)
!reference RM 3.9.2(13), 13.14(16), 6.3(5)
!from Adam Beneschan 10-03-25
!discussion
This is a wording nitpick that I'm not sure really needs to be fixed:
package Pak1 is
type T1 is tagged record ... end record;
procedure Op (X : in out T1);
end Pak1;
with Pak1;
procedure Proc2 is
type T2 is new Pak1.T1 with record ... end record;
overriding
procedure Op (X : in out T2);
Var : T2;
overriding
procedure Op (X : in out T2) is -- (A)
begin
...
end Op;
...
Shouldn't cause any problems, right? Op (on T2) is declared before
Var, which is before T2 is frozen.
However, the way things are worded:
3.9.2(13): "The explicit declaration of a primitive subprogram of a
tagged type shall occur before the type is frozen."
6.3(5): "A subprogram_body is considered a declaration. It can either
complete a previous declaration, or itself be the initial declaration
of the subprogram."
one could think that since line (A) is a declaration, and it's
occurring after the type is frozen, that 3.9.2(13) makes it illegal.
Perhaps the intent is so obvious that no fix is needed; but if it's
considered incorrect, then changing 3.9.2(13) and 13.14(16) to
something like
The explicit declaration (that is not the completion of a previous
declaration) of a primitive subprogram of a tagged type shall occur
before the type is frozen.
would work.
****************************************************************
Questions? Ask the ACAA Technical Agent