From mboxrd@z Thu Jan 1 00:00:00 1970
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Blady
Newsgroups: comp.lang.ada
Subject: Re: Raise expressions from AARM.
Date: Sun, 25 Feb 2024 12:09:08 +0100
Organization: A noiseless patient Spider
Message-ID:
References:
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 25 Feb 2024 11:09:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="4b24abc7ed527ba7b68b6767d8d8ed52";
logging-data="1916724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+hTjnu0m2PyjGk4+CmggWS"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:k13ioVHnwMg1xYgo8WYRaduk+J8=
Content-Language: fr, en-US
In-Reply-To:
Xref: news.eternal-september.org comp.lang.ada:66123
List-Id:
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.