Version 1.2 of ais/ai-00229.txt

Unformatted version of ais/ai-00229.txt version 1.2
Other versions for file ais/ai-00229.txt

!standard 3.10.2 (32)          00-04-10 AI95-00229/00
!class binding interpretation 00-04-10
!status received 00-04-10
!priority Medium
!difficulty Medium
!qualifier Omission
!subject Accessibility rules and generics
!summary
!question
The following piece of code seems to show a case where the accessibility rules allow the creation of reference to a subprogram that doesn't exist anymore.
This case doesn't seem to be caught by the "assume the worst" rule in the last sentence of RM95 3.10.2(32), because Foo is not declared in a generic body.
procedure Dangle is type Ref is access procedure; P : Ref;
generic package G is procedure Foo; end G;
package body G is X : Natural := 0;
procedure Foo is begin X := X + 1; end Foo; begin P := Foo'access; -- Legal? (Hope not.) end G;
procedure Bar is package I is new G; -- Store a reference to I.Foo in P. begin null; end Bar;
begin Bar; P.all; -- Oops, I.X is gone? end Dangle;
!recommendation
!wording
!discussion
!corrigendum xx.xx.xx(0x)
!ACATS test
!appendix

From: Pascal Leroy
Sent: Wednesday, April 05, 2000 3:54 AM

The following piece of code seems to show a case where the accessibility rules
allow the creation of reference to a subprogram that doesn't exist anymore.

This case doesn't seem to be caught by the "assume the worst" rule in the last
sentence of RM95 3.10.2(32), because Foo is not declared in a generic body.  It
seems that we either need a stronger rule (as in: "If the subprogram denoted by
P is declared within a generic, S shall be declared within the generic") or a
runtime check.

Or am I missing something?

procedure Dangle is
    type Ref is access procedure;
    P : Ref;

    generic
    package G is
        procedure Foo;
    end G;

    package body G is
        X : Natural := 0;

        procedure Foo is
        begin
            X := X + 1;
        end Foo;
    begin
        P := Foo'Access; -- You would hope that this would be illegal.
    end G;

    procedure Bar is
        package I is new G; -- Store a reference to I.Foo in P.
    begin
        null;
    end Bar;

begin
    Bar;
    P.all; -- Oops, I.X is gone?
end Dangle;

*************************************************************

From: Steve Baird
Sent: Thursday, April 06, 2000 3:44 PM

>  It seems that we either need a stronger rule (as in: "If the subprogram
> denoted by P is declared within a generic, S shall be declared within the
> generic") or a runtime check.

That rule is a little more restrictive than is necessary.

If the use of
    Some_Subprogram'Access
occurs within the spec, not the body, of the generic in which
Some_Subprogram is declared, then there is no need to
disallow the construct (because instantiation rechecking will
handle matters if the generic is instantiated in an inner scope).

How bad would it be if Ada95 suddenly started disallowing the following:

    type Ref is access procedure;

    generic
    package G is
        procedure P;
        X : Ref := P'Access;
    end G;

    package body G is ... ;

    package I is new G;

?

The notion of "inside a generic" may also need to be defined fairly
precisely in order to handle interactions with child units of generics.

*************************************************************


*************************************************************


*************************************************************


*************************************************************


Questions? Ask the ACAA Technical Agent