[net.lang.ada] Allocator Subtypes Question

Mendal@SU-SIERRA.ARPA (Geoff Mendal) (09/05/86)

Hello Ada Fans-

We've read LMC-AI 00324/02, and paragraphs 4.8:3-6 of the Language
Reference Manual, but still have a question concerning the behavior
of the following program:

  procedure Main is
    type A is access Integer range -10 .. 15;
    X : A;
  begin
    X := new Natural'(-5);
    ...
  end;

Does evaluation of the allocator raise Constraint_Error or not?
Why or why not.  We would appreciate appropriate LRM references
to back up any "interpretations".  Thanks in advance.

geoff & doug
-------

GOODENOUGH@A.ISI.EDU (John B. Goodenough) (09/05/86)

With respect to the question, does 

	X := new Natural'(-5);

raise CONSTTRAINT_ERROR, the answer is yes.  4.8(6) says the qualified
expression, Natural'(-5), is evaluated, and its evaluation raises
CONSTRAINT_ERROR [4.7(3)] regardless of what the designated subtype is.
-------

arny@bonnie.ATT.COM (09/05/86)

In article <12236430813.14.MENDAL@SU-SIERRA.ARPA> Mendal@SU-SIERRA.ARPA (Geoff Mendal) writes:
>
>We've read LMC-AI 00324/02, and paragraphs 4.8:3-6 of the Language
>Reference Manual, but still have a question concerning the behavior
>of the following program:
>
>  procedure Main is
>    type A is access Integer range -10 .. 15;
>    X : A;
>  begin
>    X := new Natural'(-5);
>    ...
>  end;
>
>Does evaluation of the allocator raise Constraint_Error or not?
>Why or why not.  We would appreciate appropriate LRM references
>to back up any "interpretations".  Thanks in advance.
>


Yes, evaluation of the allocator raises Constraint_Error because
the operand of the qualified expression used in the assignment
(-5) is not within the type mark given (Natural).

The qualified expression must be evaluated before its result can
be assigned to the object designated by X.  The appropriate
reference in the LRM is section 4.7, paragraph 3 (Qualified
Expressions).

BTW, I checked it on the (validated) AT&T UNIX Ada compiler, and
it checked out, but I don't know if the ACVC tests actually
tested that or not.  Anybody care to check?

   Thanks for a fun question, (hope the answer's correct!)
     Arny

stt@ada-uts (09/10/86)

Definitely a constraint error:
   LRM 4.8:6
      For the evaluation of an allocator, ... the evaluation of
   the qualified expression is performed first. ...

   LRM 4.7:3
      ... The evaluation of a qualified expression evaluates the operand
   and checks that its value belongs to the subtype denoted by the
   type mark.  The exception CONSTRAINT_ERROR is raised if this check
   fails. ...