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?
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
Hello,
AARM Ada 2022 section 11.3 presents some uses of raise expressions
including this one: (http://www.ada-auth.org/standards/22aarm/html/AA-11-3.html)
2.a.10/4 ...
B : Some_Array := (1, 2, 3, others => raise Not_Valid_Error);
What could be the use cases?
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?
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
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.
The point of these examples (which are only in the discussion
annotation, not in the normative standard) is to discuss what is syntactically legal and why. The examples need not make practical sense.
Le 24/02/2024 à 11:39, Niklas Holsti a écrit :
The point of these examples (which are only in the discussion
annotation, not in the normative standard) is to discuss what is
syntactically legal and why. The examples need not make practical sense.
Well, despite I knew that, I wanted to draw some use cases from them.
For instance:
A : A_Tagged := (Some_Tagged'(raise TBD_Error) with Comp => 'A');
It will raise TBD_Error if Some_Tagged is not a null record, good to
know, isn't it?
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 339 |
Nodes: | 16 (2 / 14) |
Uptime: | 00:30:32 |
Calls: | 7,466 |
Calls today: | 2 |
Files: | 12,691 |
Messages: | 5,627,864 |