comp.lang.ada
 help / color / mirror / Atom feed
* Allocator Subtypes Question
@ 1986-09-05  6:42 Geoff Mendal
  1986-09-05 12:42 ` John B. Goodenough
  1986-09-05 17:30 ` arny
  0 siblings, 2 replies; 4+ messages in thread
From: Geoff Mendal @ 1986-09-05  6:42 UTC (permalink / raw)


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
-------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Allocator Subtypes Question
  1986-09-05  6:42 Geoff Mendal
@ 1986-09-05 12:42 ` John B. Goodenough
  1986-09-05 17:30 ` arny
  1 sibling, 0 replies; 4+ messages in thread
From: John B. Goodenough @ 1986-09-05 12:42 UTC (permalink / raw)


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.
-------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Allocator Subtypes Question
  1986-09-05  6:42 Geoff Mendal
  1986-09-05 12:42 ` John B. Goodenough
@ 1986-09-05 17:30 ` arny
  1 sibling, 0 replies; 4+ messages in thread
From: arny @ 1986-09-05 17:30 UTC (permalink / raw)


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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Allocator Subtypes Question
       [not found] <14@<12236430813>
@ 1986-09-10 20:14 ` stt
  0 siblings, 0 replies; 4+ messages in thread
From: stt @ 1986-09-10 20:14 UTC (permalink / raw)



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. ...

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~1986-09-10 20:14 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <14@<12236430813>
1986-09-10 20:14 ` Allocator Subtypes Question stt
1986-09-05  6:42 Geoff Mendal
1986-09-05 12:42 ` John B. Goodenough
1986-09-05 17:30 ` arny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox