From mboxrd@z Thu Jan 1 00:00:00 1970 Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "Jeffrey R.Carter" Newsgroups: comp.lang.ada Subject: Re: Raise expressions from AARM. Date: Sat, 24 Feb 2024 11:39: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: Sat, 24 Feb 2024 10:39:08 -0000 (UTC) Injection-Info: dont-email.me; posting-host="a300bf9e1793e69cc0a30f9e974c200d"; logging-data="1204076"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/QwhVeTWgpPvbHgl90LmE4hBQQp5ZVWY8=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:yoxPbFUIZ9BOO54MQRCWj1RD/i8= Content-Language: en-US In-Reply-To: Xref: news.eternal-september.org comp.lang.ada:66120 List-Id: 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