AI22-0016-1

!standard 4.5.9(6/5)          22-02-03 AI22-0016-1/02

!class binding interpretation 21-11-12

!status Amendment 1-2022 22-02-03

!status WG9 Approved 22-10-18

!status ARG Approved 14-0-0 22-02-03

!status work item 21-11-12

!status received 21-09-16

!submitter Stephen Baird

!priority Low

!difficulty Easy

!qualifier Omission

!subject Newly constructed objects in a declare expression

!summary

Disallow renaming in a declare expression any part of a newly constructed object or value conversion of a limited type, to avoid having to worry about tasks and build-in-place.

!issue

In 4.5.9(6/5) we have:

A declare_item that is an object_renaming_declaration (see 8.5.1) shall not rename an object of a limited type if any operative constituent of the object_name is a value conversion or is newly constructed (see 4.4).

So I think this allows (inside a declare expression) something like

X : Limited_Type renames Function_Returning_Array_Of_Tasks (1 .. 10);

This is a slice of a newly constructed object, which seems just as bad as a newly constructed object, since it still might contain a "new" task. Do we want to allow this? (No)

!recommendation

We should also disallow cases where we are renaming any part of a newly constructed object that might contain a new task.

!wording

Modify 4.5.9(6/5):

A declare_item that is an object_renaming_declaration (see 8.5.1) shall not rename an object of a limited type if any operative constituent of the object_name is {part of} a value conversion or is {part of a} newly constructed {object} (see 4.4).

!discussion

We could not accomplish what we want by changing the definition of "newly constructed", because it is already exactly what we want when we are saying that something must be (as opposed to must not be) newly constructed. So instead we have changed this use of the term newly constructed object, to include parts thereof. We have also disallowed renaming parts of a value conversion of a limited type, since the operand of a value conversion might be newly constructed.

!corrigendum 4.5.9(6/5)

@drepl
A @fa{declare_item} that is an @fa{object_renaming_declaration} (see @ref{8.5.1}) shall not rename an object of a limited type if any operative constituent of the @i{object_}@fa{name} is a value conversion or is newly constructed (see @ref{4.4}).
@dby
A @fa{declare_item} that is an @fa{object_renaming_declaration} (see @ref{8.5.1}) shall not rename an object of a limited type if any operative constituent of the @i{object_}@fa{name} is part of a value conversion or is part of a newly constructed object (see @ref{4.4}).

!ACATS test

An ACATS B-Test should check the modified rule with cases like that in the example.

!appendix

From: Steve Baird [privately]

Sent: Thursday, September 16, 2021 7:12 PM

We've got

  A declare_item that is an object_renaming_declaration (see 8.5.1) shall

  not rename an object of a limited type if any operative constituent of

  the object_name is a value conversion or is newly constructed (see 4.4).

Note that an indexed component or a selected component or a slice

is never newly constructed. This is fine when we are requiring that something must

be newly constructed, but not so good (I think) in the opposite case.

So I think this allows (inside a declare expression) something like

      X : Limited_Type renames Function_Returning_Array_Of_Tasks (1 .. 10);

which I don't think we wanted to allow.

Is there a problem here, or am I confused?

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

From: Tucker Taft [privately]

Sent: Thursday, September 16, 2021 7:27 PM

Good point. Probably need to add to the definition of "newly constructed"

something like "or part thereof". E.g.:

9.7/5 {AI12-0317-1} In certain contexts, we specify that an operative

constituent shall (or shall not) be newly constructed. This means the

operative constituent shall (or shall not) be an aggregate or a

function_call{, or part thereof}; in either case, a raise_expression is

permitted.

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

From: Steve Baird [privately]

Sent: Thursday, September 16, 2021 8:01 PM

We don't want to allow

    function F return Limited_Type is

    begin

         return Limited_Type'(<some aggregate>)(1 .. 10);

     end;

I believe the wording change you proposed would allow this case.

I don't think we can accomplish what we want by changing the definition of

"newly constructed", because it is already exactly what we want when we

are saying that something must be (as opposed to must not be) newly

constructed.

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

From: Tucker Taft [privately]

Sent: Thursday, September 16, 2021 8:41 PM

Make sense. So the fix needs to be a restriction in declare expressions,

where we are trying to avoid having anything that needs finalization. Hence:

6/5{AI12-0236-1} {AI12-0317-1} A declare_item that is an

object_renaming_declaration (see 8.5.1) shall not rename an object of a

limited type if any operative constituent of the object_name is {part of}

a value conversion or is {part of a} newly constructed {object} (see 4.4).

I am not sure about the value conversion case, since I don't remember why

it is there in the first place. But adding "part of" in seems prudent

there as well.

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

From: Steve Baird [privately]

Sent: Thursday, September 16, 2021 9:39 PM

Sounds good. I think the value conversion part of the wording is there to

avoid another case where a new object that requires finalization can be

created.

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