comp.lang.ada
 help / color / mirror / Atom feed
From: "Jeffrey R.Carter" <spam.jrcarter.not@spam.acm.org.not>
Subject: Re: Raise expressions from AARM.
Date: Sat, 24 Feb 2024 11:39:08 +0100	[thread overview]
Message-ID: <urch0c$14nrc$1@dont-email.me> (raw)
In-Reply-To: <urce58$14j88$1@dont-email.me>

On 2024-02-24 10:50, Blady wrote:
> 
> My guess: whatever the size of Some_Array (greater than 3), B is elaborated but 
> raises Not_Valid_Error when accessing component beyond position 3:
> 
> type Some_Array is array (Positive range 1..10) of Natural;
> ...
> B : Some_Array := (1, 2, 3, others => raise Not_Valid_Error);
> ...
> begin
> X := B (2); -- OK
> X := B (6); -- raises Not_Valid_Error
> end;
> 
> Is it correct?

No. This will raise the exception upon the elaboration of B.

The only use of this that I can imagine is if the length of Some_Array is 3. 
Then the others choice is null, so the raise expression is never evaluated. But 
if someone changes the definition of Some_Array to be longer, then the exception 
will be raised.

> NB: GNAT 13.2 issues a compilation error:
>          >>> error: "others" choice not allowed here
> see: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113862

The example in the error report has Some_Array unconstrained, in which case an 
others choice is not allowed. With the constrained definition given above, the 
aggregate is valid.

-- 
Jeff Carter
"Gentlemen, you can't fight in here. This is the War Room!"
Dr. Strangelove
30

  reply	other threads:[~2024-02-24 10:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-24  9:50 Raise expressions from AARM Blady
2024-02-24 10:39 ` Jeffrey R.Carter [this message]
2024-02-25 11:09   ` Blady
2024-02-24 10:39 ` Niklas Holsti
2024-02-25 11:23   ` Blady
2024-02-26 20:01     ` Niklas Holsti
replies disabled

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