comp.lang.ada
 help / color / mirror / Atom feed
From: Blady <p.p11@orange.fr>
Subject: Re: Raise expressions from AARM.
Date: Sun, 25 Feb 2024 12:09:08 +0100	[thread overview]
Message-ID: <urf74l$1qfpk$1@dont-email.me> (raw)
In-Reply-To: <urch0c$14nrc$1@dont-email.me>

Le 24/02/2024 à 11:39, Jeffrey R.Carter a écrit :
> 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.

If I understand well, no compiler error nor warning at compilation time 
but Not_Valid_Error raised at run time elaboration.
To be compared with:
    B1 : Some_Array := (1, 2, 3);
No compiler error, one compiler warning "Constraint_Error will be raised 
at run time" and Constraint_Error range check failed raised at run time 
elaboration.

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

Thanks to point out, I've corrected the GNAT report.

Pascal.

  reply	other threads:[~2024-02-25 11:09 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
2024-02-25 11:09   ` Blady [this message]
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