CVS difference for ai05s/ai05-0050-1.txt
--- ai05s/ai05-0050-1.txt 2008/06/14 07:05:32 1.3
+++ ai05s/ai05-0050-1.txt 2008/10/16 01:00:25 1.4
@@ -1,4 +1,4 @@
-!standard 6.5(24/2) 08-06-13 AI05-0050-1/03
+!standard 6.5(24/2) 08-10-10 AI05-0050-1/04
!class binding interpretation 07-05-04
!status work item 07-05-04
!status received 07-04-20
@@ -11,8 +11,8 @@
If an object is being initialized by a function call and the implementation
can tell before the call that the object subtype and the function result
-subtype are incompatible, then the implementation should be permitted
-to raise an exception before the call.
+subtype are incompatible, then the implementation is permitted to raise
+an exception before the call.
If the object declared in an extended return statement is unconstrained,
has discriminants, and is nonlimited, the existing permission does not apply.
@@ -53,141 +53,24 @@
For a function call used to initialize a composite object with a constrained
nominal subtype:
- - If the result subtype of the function is constrained, and does not match
- that of the object, Constraint_Error may be raised before calling the
- function.
-
- - Otherwise (the result subtype of the function is unconstrained), if a
- return statement is executed such that the return object is known to be
- constrained, and this constraint does not match that of the object,
+ - If the result subtype of the function is constrained, and conversion of
+ an object of this subtype to the subtype of the object being initialized
+ would raise Constraint_Error, then Constraint_Error may be raised before
+ calling the function.
+
+ - If the result subtype of the function is unconstrained, and a return
+ statement is executed such that the return object is known to be
+ constrained, and conversion of the return object to the subtype of the
+ object being initialized would raise Constraint_Error, then
Constraint_Error may be raised at the point of the call (after abandoning
the execution of the function body).
- If the function call is used to provide the initial value of an
- initialized allocator, then the call to System.Storage_Pools.Allocate
- may occur at any time during the execution of the call.
- If a return statement is left without a normal return, the result
- object may be deallocated.
-
AARM Notes
These permissions apply transitively in the case of a function call
- which returns the value of another function call. In the following example,
-
- declare
- type T is
- limited record
- ... ;
- end record;
- -- requires in-place initialization
-
- type Unconstrained is array (Positive range <>) of T;
-
- function Some_Function return T is ... ;
-
- function F1 return Unconstrained is
- begin
- return (1 .. 10 => Some_Function);
- end F1;
-
- function F2 return Unconstrained is
- begin
- return F1;
- end F2;
-
- X : Unconstrained (1..3) := F2;
- begin
- null;
- end;
-
- , Constraint_Error may be raised in F1 before any calls to Some_Function
- are executed.
-
- Consider:
-
- declare
- type T is
- limited record
- ... ;
- end record;
- -- requires in-place initialization
+ which returns the value of another function call.
- type Unconstrained is array (Positive range <>) of T;
-
- subtype Constrained is T (1 .. 3);
-
- function Some_Function return T is ... ;
- function F1 return Unconstrained is
- begin return (1.. 10 => Some_Function); end;
-
- function F2 return Constrained is begin return F1; end if;
-
- function F3 return Unconstrained is
- begin
- return Constrained'(F1);
- end F3;
-
-
- begin
- begin
- declare
- X : Unconstrained := F2;
- begin null; end;
- exception when Constraint_Error => null;
- end;
-
- begin
- declare
- X : Unconstrained := F3;
- begin null; end;
- exception when Constraint_Error => null;
- end;
-
- begin
- declare
- X : Unconstrained := Constrained'(F1);
- begin null; end;
- exception when Constraint_Error => null;
- end;
- end;
-
- In all three of these cases, Constraint_Error may be raised in F1 before
- the execution of any calls to Some_Function.
-
- Note that these permissions do not apply in the
- case of an extended return object with mutable discriminants.
- For example:
-
- declare
- type T (Is_Big : Boolean := True) is
- record
- case Is_Big is
- when False => null;
- when True => Big_Component : String (1..1024) := (others => 'X');
- end case;
- end record;
-
- function F return T is
- begin
- return X : T do -- X is unconstrained
- X.Big_Component := (others => 'Y');
- X := (Is_Big => False);
- end return;
- end F;
-
- Small_Object : T (Is_Big => False) := F;
- begin
- null;
- end;
-
- and so Constraint_Error must not be raised (which is good).
-
- Note that this mutable-discriminant case only happens when
- in-place initialization is optional. This means that any difficulties
- associated with implementing in-place initialization without these
- permissions can be sidestepped.
-
!discussion
The implementation permissions of 6.5(24/2) do not go far enough.
@@ -263,7 +146,7 @@
Y : S1 := S2'(F);
-, but this doesn't seem necessary.
+but this doesn't seem necessary.
--------
@@ -414,43 +297,124 @@
----
-The mention of System.Storage_Pools.Deallocate is needed to allow
-implementations to avoid storage leaks. Consider the following example:
- declare
- type T is
- limited record
- ... ;
- end record;
- -- requires in-place initialization
+With the revised wording, in the following example,
+
+ declare
+ type T is
+ limited record
+ ... ;
+ end record;
+ -- requires in-place initialization
- type Unconstrained is array (Positive range <>) of T;
+ type Unconstrained is array (Positive range <>) of T;
+
+ function Some_Function return T is ... ;
- function F1 return Unconstrained is
- Result_Length : Natural := 10;
+ function F1 return Unconstrained is
+ begin
+ return (1 .. 10 => Some_Function);
+ end F1;
+
+ function F2 return Unconstrained is
+ begin
+ return F1;
+ end F2;
+
+ X : Unconstrained (1..3) := F2;
+ begin
+ null;
+ end;
+
+Constraint_Error may be raised in F1 before any calls to Some_Function
+are executed.
+
+Similarly:
+
+ declare
+ type T is
+ limited record
+ ... ;
+ end record;
+ -- requires in-place initialization
+
+ type Unconstrained is array (Positive range <>) of T;
+
+ subtype Constrained is T (1 .. 3);
+
+ function Some_Function return T is ... ;
+
+ function F1 return Unconstrained is
+ begin return (1.. 10 => Some_Function); end;
+
+ function F2 return Constrained is begin return F1; end if;
+
+ function F3 return Unconstrained is
+ begin
+ return Constrained'(F1);
+ end F3;
+
+
begin
- for Really_Return in Boolean loop
- Result_Length := Result_Length * 2;
- return Result : Unconstrained (1 .. Result_Length) do
- ...;
- if not Really_Return then goto L;
+ begin
+ declare
+ X : Unconstrained := F2;
+ begin null; end;
+ exception when Constraint_Error => null;
+ end;
+
+ begin
+ declare
+ X : Unconstrained := F3;
+ begin null; end;
+ exception when Constraint_Error => null;
+ end;
+
+ begin
+ declare
+ X : Unconstrained := Constrained'(F1);
+ begin null; end;
+ exception when Constraint_Error => null;
+ end;
+ end;
+
+In all three of these cases, Constraint_Error may be raised in F1 before
+the execution of any calls to Some_Function.
+
+Note that these permissions do not apply in the
+case of an extended return object with mutable discriminants.
+For example:
+
+ declare
+ type T (Is_Big : Boolean := True) is
+ record
+ case Is_Big is
+ when False => null;
+ when True => Big_Component : String (1..1024) := (others => 'X');
+ end case;
+ end record;
+
+ function F return T is
+ begin
+ return X : T do -- X is unconstrained
+ X.Big_Component := (others => 'Y');
+ X := (Is_Big => False);
end return;
- <<L>> null;
- end loop;
- end F1;
-
- type Unconstrained_Ref is access Unconstrained;
- for Unconstrained_Ref'Storage_Pool use ... ;
-
- Ptr : Unconstrained_Ref := new Unconstrained'(F1);
- begin
- ...;
- end;
+ end F;
+
+ Small_Object : T (Is_Big => False) := F;
+ begin
+ null;
+ end;
+
+and so Constraint_Error must not be raised (which is good).
-The execution of this example may involve two calls to
-System.Storage_Pools.Allocate. We do not want to require that implementations
-clean up after the first call by calling Deallocate,
-but we do want to give implementations that option.
+Note that this mutable-discriminant case only happens when
+in-place initialization is optional. This means that any difficulties
+associated with implementing in-place initialization without these
+permissions can be sidestepped.
+
+
!ACATS test
@@ -1051,5 +1015,21 @@
And then the examples in the current AI should be moved to the discussion (and
probably lots of the discussion blown away).
+
+****************************************************************
+
+From: Bob Duff
+Sent: Friday, October 10, 2008 3:21 PM
+
+Here's a (belated) new version of AI-50. [This is version /04. - ED]
+
+I tried to obey the stuff in the minutes. But I didn't define the term "dynamically
+matching". I couldn't figure out any way to do so, other than the attempts recorded
+in the minutes, which apparently folks didn't like. Anyway, it seems better to
+just state the rule, rather than defining yet more jaw-breaking terminology,
+especially since the term is used only for this one rule.
+
+I removed the stuff about Allocate and Deallocate, because that will be covered
+by AI-107, as I understand it.
****************************************************************
Questions? Ask the ACAA Technical Agent