Debian Codegraph @

source_2005/11.mss

raw
1 @Part(11, Root="ada.mss")
2
3 @Comment{$Date: 2006/10/19 20:44:13 $}
4 @LabeledSection{Exceptions}
5
6 @Comment{$Source: e:\\cvsroot/ARM/Source/11.mss,v $}
7 @Comment{$Revision: 1.64 $}
8
9 @begin{Intro}
10 @redundant[This section defines the facilities for dealing with errors or other
11 exceptional situations that arise during program execution.]
12 @Defn{exception occurrence}
13 @IndexSeeAlso{Term=[condition],See=(exception)}
14 @IndexSee{Term=[signal (an exception)],See=(raise)}
15 @IndexSee{Term=[throw (an exception)],See=(raise)}
16 @IndexSee{Term=[catch (an exception)],See=(handle)}
17 @ToGlossaryAlso{Term=<Exception>,
18 Text=<An @i(exception) represents a kind of exceptional situation;
19 an occurrence of such a situation (at run time)
20 is called an @i(exception occurrence).
21 @redundant[@PDefn2{Term=[raise], Sec=(an exception)}
22 To @i{raise} an exception is to abandon normal program execution so
23 as to draw attention to the fact that the corresponding situation has
24 arisen.
25 @PDefn2{Term=[handle], Sec=(an exception)}
26 Performing some actions in response to the arising of an exception
27 is called @i{handling} the exception.
28 ]>}
29 @begin{Honest}
30 @PDefn2{Term=[handle], Sec=(an exception occurrence)}
31 ...or handling the exception occurrence.
32 @end{Honest}
33 @begin{Ramification}
34 For example, an exception End_Error might
35 represent error situations in which an attempt is made to read beyond
36 end-of-file. During the execution of a partition, there might be
37 numerous occurrences of this exception.
38 @end{Ramification}
39 @begin{Honest}
40 @Defn{occurrence (of an exception)}
41 When the meaning is clear from the context,
42 we sometimes use @lquotes@;@i{occurrence}@rquotes@; as a
43 short-hand for @lquotes@;exception occurrence.@rquotes@;
44 @end{Honest}
45
46 @redundant[An @nt{exception_declaration} declares a name for an exception.
47 An exception is raised initially either by a @nt{raise_statement}
48 or by the failure of a language-defined check.
49 When an exception arises, control can be transferred to a
50 user-provided @nt{exception_handler} at the end of a
51 @nt{handled_@!sequence_of_@!statements},
52 or it can be propagated to a dynamically enclosing execution.]
53 @end{Intro}
54
55 @begin{DiffWord83}
56 We are more explicit about the difference between an exception and an
57 occurrence of an exception.
58 This is necessary because we now have a type (Exception_Occurrence)
59 that represents exception occurrences,
60 so the program can manipulate them.
61 Furthermore, we say that when an exception is propagated,
62 it is the same occurrence that is being propagated
63 (as opposed to a new occurrence of the same exception).
64 The same issue applies to a re-raise statement.
65 In order to understand these semantics,
66 we have to make this distinction.
67 @end{DiffWord83}
68
69 @LabeledClause{Exception Declarations}
70
71 @begin{Intro}
72 @Defn{exception}
73 An @nt{exception_declaration} declares a name for an
74 exception.
75 @end{Intro}
76
77 @begin{Syntax}
78 @Syn{lhs=<exception_declaration>,rhs="@Syn2{defining_identifier_list} : @key{exception};"}
79 @end{Syntax}
80
81 @begin{StaticSem}
82 Each single @nt{exception_declaration} declares a name for a different
83 exception. If a generic unit includes an @nt{exception_declaration},
84 the @nt{exception_declaration}s implicitly generated by
85 different instantiations of the generic unit refer to distinct
86 exceptions (but all have the same @nt{defining_identifier}).
87 The particular exception denoted by an exception name is determined at
88 compilation time and is the same regardless of how many times the
89 @nt{exception_declaration} is elaborated.
90 @begin{Reason}
91 We considered removing this requirement
92 inside generic bodies,
93 because it is an implementation burden for implementations
94 that wish to share code among several instances.
95 In the end, it was decided that it
96 would introduce too much implementation dependence.
97 @end{Reason}
98 @begin{Ramification}
99 Hence, if an @nt{exception_declaration} occurs in a recursive
100 subprogram, the exception name denotes the same exception for all
101 invocations of the recursive subprogram.
102 The reason for this rule is that we allow an exception occurrence to
103 propagate out of its declaration's innermost containing master;
104 if exceptions were created by their declarations like other entities,
105 they would presumably be destroyed upon leaving the master;
106 we would have to do something special to prevent them from
107 propagating to places where they no longer exist.
108 @end{Ramification}
109 @begin{Ramification}
110 Exception identities are unique across all partitions of a
111 program.
112 @end{Ramification}
113
114 @Defn{predefined exception}
115 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
116 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
117 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
118 @Defn2{Term=[Tasking_Error],Sec=(raised by failure of run-time check)}
119 The @i{predefined} exceptions are the ones declared in the
120 declaration of package Standard:
121 Constraint_Error, Program_Error,
122 Storage_Error, and Tasking_Error@Redundant[;
123 one of them is raised when a language-defined check fails.]
124 @begin{Ramification}
125 The exceptions declared in the
126 language-defined package IO_Exceptions, for example,
127 are not predefined.
128 @end{Ramification}
129 @end{StaticSem}
130
131 @begin{RunTime}
132 @PDefn2{Term=[elaboration], Sec=(exception_declaration)}
133 The elaboration of an @nt{exception_declaration} has no effect.
134
135 @IndexCheck{Storage_Check}
136 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
137 The execution of any construct raises Storage_Error if there is
138 insufficient storage for that execution.
139 @PDefn{unspecified}
140 The amount of storage needed for the execution of constructs is
141 unspecified.
142 @begin{Ramification}
143 Note that any execution whatsoever can raise Storage_Error.
144 This allows much implementation freedom in storage management.
145 @end{Ramification}
146 @end{RunTime}
147
148 @begin{Examples}
149 @leading@keepnext@i{Examples of user-defined exception declarations:}
150 @begin{Example}
151 Singular : @key[exception];
152 Error : @key[exception];
153 Overflow, Underflow : @key[exception];
154 @end{Example}
155 @end{Examples}
156
157 @begin{Inconsistent83}
158 @Defn{inconsistencies with Ada 83}
159 The exception Numeric_Error is now defined in the Obsolescent
160 features Annex, as a rename of Constraint_Error.
161 All checks that raise Numeric_Error in Ada 83
162 instead raise Constraint_Error in Ada 95.
163 To increase upward compatibility,
164 we also changed the rules to allow the same exception to be named
165 more than once by a given handler.
166 Thus,
167 @lquotes@;@key[when] Constraint_Error | Numeric_Error =>@rquotes@; will remain
168 legal in Ada 95,
169 even though Constraint_Error and Numeric_Error now denote the same
170 exception. However, it will not be legal to have
171 separate handlers for Constraint_Error and Numeric_Error.
172 This change is inconsistent in the rare case that an
173 existing program explicitly raises Numeric_Error at a point where
174 there is a handler for Constraint_Error;
175 the exception will now be caught by that handler.
176 @end{Inconsistent83}
177
178 @begin{DiffWord83}
179 We explicitly define elaboration for @nt{exception_declaration}s.
180 @end{DiffWord83}
181
182 @LabeledClause{Exception Handlers}
183
184 @begin{Intro}
185 @redundant[The response to one or more exceptions is specified by an
186 @nt{exception_handler}.]
187 @end{Intro}
188
189 @begin{Syntax}
190 @Syn{lhs=<handled_sequence_of_statements>,rhs="
191 @Syn2{sequence_of_statements}
192 [@key{exception}
193 @Syn2{exception_handler}
194 {@Syn2{exception_handler}}]"}
195
196
197 @Syn{lhs=<exception_handler>,rhs="
198 @key{when} [@Syn2{choice_parameter_specification}:] @Syn2{exception_choice} {| @Syn2{exception_choice}} =>
199 @Syn2{sequence_of_statements}"}
200
201 @Syn{lhs=<choice_parameter_specification>,rhs="@Syn2{defining_identifier}"}
202
203 @Syn{lhs=<exception_choice>,rhs="@SynI{exception_}@Syn2{name} | @key{others}"}
204 @begin{Honest}
205 @Defn{handler}
206 @lquotes@;@i{Handler}@rquotes@; is an abbreviation for @lquotes@;@nt{exception_handler}.@rquotes@;
207
208 @Defn2{term=<choice>, Sec=<of an @nt{exception_handler}>}
209 Within this section, we sometimes abbreviate
210 @lquotes@;@nt{exception_choice}@rquotes@; to @lquotes@;@i{choice}.@rquotes@;
211 @end{Honest}
212 @end{Syntax}
213
214 @begin{Legality}
215 @Defn2{term=<cover>, Sec=<of a choice and an exception>}
216 A choice with an
217 @SynI{exception_}@nt{name} @i{covers} the named exception.
218 A choice with @key{others} covers all exceptions
219 not named by previous choices of the same
220 @nt{handled_@!sequence_of_@!statements}.
221 Two choices in different @nt<exception_handler>s of the same
222 @nt{handled_@!sequence_of_@!statements} shall not cover the same
223 exception.
224 @begin{Ramification}
225 Two @nt<exception_choice>s of the same @nt<exception_handler> may cover
226 the same exception. For example, given two renaming declarations in
227 separate packages for the same exception, one may nevertheless
228 write, for example,
229 @lquotes@;@key[when] Ada.Text_IO.Data_Error | My_Seq_IO.Data_Error =>@rquotes@;.
230
231 An @key{others} choice even covers exceptions that are not
232 visible at the place of the handler.
233 Since exception raising is a dynamic activity,
234 it is entirely possible for an @key{others} handler to handle an
235 exception that it could not have named.
236 @end{Ramification}
237
238 A choice with @key{others} is allowed only for the
239 last handler of a @nt{handled_sequence_of_statements}
240 and as the only choice of that handler.
241
242 An @SynI{exception_}@nt{name} of a choice shall not denote an
243 exception declared in a generic formal package.
244 @begin{Reason}
245 This is because the compiler doesn't know the identity of such an
246 exception, and thus can't enforce the coverage rules.
247 @end{Reason}
248 @end{Legality}
249
250 @begin{StaticSem}
251 @Defn{choice parameter}
252 A @nt{choice_parameter_specification} declares a
253 @i{choice parameter}, which is a constant object of type
254 Exception_Occurrence (see @RefSecNum{The Package Exceptions}).
255 During the handling of an exception occurrence,
256 the choice parameter, if any, of the handler
257 represents the exception occurrence that is being handled.
258
259 @end{StaticSem}
260
261 @begin{RunTime}
262 @PDefn2{Term=[execution], Sec=(handled_sequence_of_statements)}
263 The execution of a @nt<handled_sequence_of_statements> consists
264 of the execution of the @nt<sequence_of_@!statements>.
265 @Redundant[The optional handlers are used to handle any exceptions
266 that are propagated by the @nt{sequence_of_@!statements}.]
267 @end{RunTime}
268
269 @begin{Examples}
270 @leading@keepnext@i{Example of an exception handler:}
271 @begin{Example}
272 @key[begin]
273 Open(File, In_File, "input.txt"); --@RI[ see @RefSecNum{File Management}]
274 @key[exception]
275 @key[when] E : Name_Error =>
276 Put("Cannot open input file : ");
277 Put_Line(Exception_Message(E)); --@RI[ see @RefSecNum{The Package Exceptions}]
278 @key[raise];
279 @key[end];
280 @end{Example}
281 @end{Examples}
282
283 @begin{Extend83}
284 @Defn{extensions to Ada 83}
285 The syntax rule for @nt{exception_handler} is modified to
286 allow a @nt{choice_parameter_specification}.
287
288 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00114-01]}
289 Different @Chg{Version=[2],New=[@nt{exception_choice}s],Old=[@ntf<choice>s]}
290 of the same @nt<exception_handler> may
291 cover the same exception. This allows for
292 @lquotes@;when Numeric_Error | Constraint_Error =>@rquotes@; even though
293 Numeric_Error is a rename of Constraint_Error.
294 This also allows one to @lquotes@;with@rquotes@; two different I/O packages,
295 and then write, for example,
296 @lquotes@;when Ada.Text_IO.Data_Error | My_Seq_IO.Data_Error =>@rquotes@;
297 even though these might both be renames of the same exception.
298 @end{Extend83}
299
300 @begin{DiffWord83}
301 The syntax rule for @nt{handled_sequence_of_statements} is new.
302 These are now used in all the places where handlers
303 are allowed.
304 This obviates the need to explain
305 (in Sections 5, 6, 7, and 9)
306 what portions of the program are handled by the handlers.
307 Note that there are more such cases in Ada 95.
308
309 The syntax rule for @nt{choice_parameter_specification} is new.
310 @end{DiffWord83}
311
312 @LabeledClause{Raise Statements}
313
314 @begin{Intro}
315 @redundant[A @nt{raise_statement} raises an exception.]
316 @end{Intro}
317
318 @begin{Syntax}
319 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00361-01]}
320 @Syn{lhs=<raise_statement>,rhs="@Chg{Version=[2],New=<@key{raise};
321 | @key{raise} @SynI{exception_}@Syn2{name} [@key{with} @SynI{string_}@Syn2{expression}];>,
322 Old=<@key{raise} [@SynI{exception_}@Syn2{name}];>}"}
323 @end{Syntax}
324
325 @begin{Legality}
326 The @nt{name}, if any, in a @nt{raise_statement} shall denote
327 an exception.
328 @Defn{re-raise statement}
329 A @nt{raise_statement} with no @SynI{exception_}@nt{name}
330 (that is, a @i{re-raise statement})
331 shall be within a handler,
332 but not within a body enclosed by that handler.
333 @end{Legality}
334
335 @begin{Resolution}
336 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00361-01]}
337 @ChgAdded{Version=[2],Text=[The @nt<expression>, if any, in a
338 @nt<raise_statement>, is expected to be of type String.]}
339 @end{Resolution}
340
341 @begin{RunTime}
342 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00361-01]}
343 @Defn2{Term=[raise], Sec=(an exception)}
344 To @i(raise an exception) is to
345 raise a new occurrence of that exception@Redundant[,
346 as explained in @RefSecNum{Exception Handling}].
347 @PDefn2{Term=[execution], Sec=(raise_statement with an exception_name)}
348 For the execution of a @nt{raise_statement} with an
349 @SynI{exception_}@nt{name}, the named exception is raised.
350 @Chg{Version=[2],New=[@redundant{If a @SynI<string_>@nt<expression> is present,
351 the @nt{expression} is evaluated and its value is associated with the
352 exception occurrence.}],Old=[]}
353 @PDefn2{Term=[execution], Sec=(re-raise statement)}
354 For the execution of a re-raise statement,
355 the exception occurrence that caused transfer of control to the
356 innermost enclosing handler is raised @Redundant[again].
357 @begin{TheProof}
358 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00361-01]}
359 @ChgAdded{Version=[2],Text=[The definition of Exceptions.Exception_Message
360 includes a statement that the string is returned (see
361 @RefSecNum{The Package Exceptions}). We describe the use of the string
362 here so that we don't have an unexplained parameter in this subclause.]}
363 @end{TheProof}
364 @begin{ImplNote}
365 For a re-raise statement, the implementation does not create a new
366 Exception_Occurrence, but instead propagates the same
367 Exception_Occurrence value.
368 This allows the original cause of the exception to be determined.
369 @end{ImplNote}
370 @end{RunTime}
371
372 @begin{Examples}
373 @leading@keepnext@i{Examples of raise statements:}
374 @begin{Example}
375 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
376 @key[raise] Ada.IO_Exceptions.Name_Error; --@RI[ see @RefSecNum{Exceptions In Input-Output}]@Chg{Version=[2],New=[
377 @key[raise] Queue_Error @key[with] "Buffer Full"; --@RI[ see @RefSecNum{Example of Tasking and Synchronization}]],Old=[]}
378
379 @key[raise]; --@RI[ re-raise the current exception]
380 @end{Example}
381 @end{Examples}
382
383 @begin{DiffWord83}
384 The fact that the @nt{name} in a @nt{raise_statement} has to denote
385 an exception is not clear from RM83.
386 Clearly that was the intent,
387 since the italicized part of the syntax rules so indicate,
388 but there was no explicit rule.
389 RM83-1.5(11) doesn't seem to give the italicized parts of the syntax
390 any force.
391 @end{DiffWord83}
392
393 @begin{Extend95}
394 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00361-01]}
395 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}The syntax of a
396 @nt{raise_statement} is extended to include a string message. This is more
397 convenient than calling Exceptions.Exception_Message
398 (@SynI{exception_}@nt{name}'Identity, @SynI{string_}@nt{expression}), and
399 should encourage the use of message strings when raising exceptions.]}
400 @end{Extend95}
401
402
403 @LabeledClause{Exception Handling}
404
405 @begin{Intro}
406 @redundant[When an exception occurrence is raised,
407 normal program execution is abandoned
408 and control is transferred to an applicable @nt{exception_handler},
409 if any.
410 @Defn2{Term=[handle], Sec=(an exception occurrence)}
411 To @i(handle) an exception occurrence is to respond to the
412 exceptional event.
413 @Defn{propagate}
414 To @i(propagate) an exception occurrence is to raise it again in
415 another context; that is,
416 to fail to respond to the exceptional event in the present context.]
417 @begin{Ramification}
418 In other words, if the execution of a given construct raises an exception,
419 but does not handle it,
420 the exception is propagated to an enclosing execution
421 (except in the case of a @nt{task_body}).
422
423 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{Presentation AI-00023}
424 Propagation involves re-raising the same exception occurrence@Chg{New=[],
425 Old=[(assuming the implementation has not taken advantage of the
426 @ImplPermName of @RefSecNum{Raise Statements})]}.
427 For example, calling an entry of an uncallable task raises
428 Tasking_Error; this is not propagation.
429 @end{Ramification}
430 @end{Intro}
431
432 @begin{RunTime}
433 @Defn2{Term=[dynamically enclosing], Sec=(of one execution by another)}
434 @Defn2{Term=[execution], Sec=(dynamically enclosing)}
435 Within a given task, if the
436 execution of construct @i{a} is defined by this International Standard
437 to consist (in part) of the
438 execution of construct @i{b}, then while @i{b} is executing, the
439 execution of @i{a} is said to @i(dynamically enclose) the execution of
440 @i{b}.
441 @Defn{innermost dynamically enclosing}
442 The @i(innermost
443 dynamically enclosing) execution of a given execution is the
444 dynamically enclosing execution that started most recently.
445 @begin{Honest}
446 @Defn2{Term=[included], Sec=(one execution by another)}
447 @Defn2{Term=[execution], Sec=(included by another execution)}
448 If the execution of @i{a} dynamically encloses that of @i{b},
449 then we also say that the execution of @i{b} is
450 @i{included in} the execution of @i{a}.
451 @end{Honest}
452 @begin{Ramification}
453 Examples: The execution of an @nt{if_statement}
454 dynamically encloses the evaluation of the @nt{condition} after the
455 @key{if} (during that evaluation).
456 (Recall that @lquotes@;execution@rquotes@; includes both @lquotes@;elaboration@rquotes@; and
457 @lquotes@;evaluation@rquotes@;, as well as other executions.)
458 The evaluation of a function call dynamically encloses the execution
459 of the @nt{sequence_of_statements} of the function @nt{body}
460 (during that execution). Note that, due to recursion, several
461 simultaneous executions of the same construct can be occurring at once
462 during the execution of a particular task.
463
464 Dynamically enclosing is not defined across task boundaries;
465 a task's execution does not include the execution of any other tasks.
466
467 Dynamically enclosing is only defined for executions that are occurring
468 at a given moment in time; if an @nt{if_statement} is currently
469 executing the @nt{sequence_of_statements} after @key{then}, then
470 the evaluation of the @nt{condition} is no longer dynamically
471 enclosed by the execution of the @nt{if_statement} (or anything else).
472 @end{Ramification}
473
474 @Leading@Defn2{Term=[raise], Sec=(an exception occurrence)}
475 When an exception occurrence is raised by the execution of a given
476 construct, the rest of the execution of that construct is @i{abandoned};
477 that is, any portions of the execution that have not yet taken place
478 are not performed.
479 The construct is first completed, and then left, as explained
480 in @RefSecNum{Completion and Finalization}.
481 Then:
482 @begin{Itemize}
483 If the construct is a @nt<task_body>,
484 the exception does not propagate further;
485 @begin{Ramification}
486 When an exception is raised by the execution of a
487 @nt{task_body}, there is no dynamically enclosing execution,
488 so the exception does not propagate any further.
489 If the exception occurred during
490 the activation of the task, then the activator raises Tasking_Error,
491 as explained in @RefSec{Task Execution - Task Activation},
492 but we don't define that as propagation; it's a special rule.
493 Otherwise (the exception occurred during the execution of the
494 @nt{handled_sequence_of_statements} of the task),
495 the task silently disappears.
496 Thus, abnormal termination of tasks is not always considered to be an
497 error.
498 @end{Ramification}
499
500 If the construct is the @nt{sequence_of_statements} of a
501 @nt{handled_sequence_of_statements} that has a
502 handler with a choice covering the exception,
503 the occurrence is handled by that handler;
504
505 @Defn2{Term=[propagate],
506 Sec=(an exception occurrence by an execution, to a dynamically enclosing execution)}
507 Otherwise, the occurrence is @i{propagated}
508 to the innermost dynamically enclosing execution,
509 which means that the occurrence is raised again
510 in that context.
511 @begin{Honest}
512 @Defn2{Term=[propagate], Sec=(an exception by an execution)}
513 @Defn2{Term=[propagate], Sec=(an exception by a construct)}
514 As shorthands, we refer to the @i{propagation of an exception},
515 and the @i{propagation by a construct},
516 if the execution of the construct propagates an exception occurrence.
517 @end{Honest}
518 @end{Itemize}
519
520 @Defn2{Term=[handle], Sec=(an exception occurrence)}
521 @PDefn2{Term=[execution], Sec=(handler)}
522 @PDefn2{Term=[elaboration], Sec=(choice_parameter_specification)}
523 When an occurrence is @i(handled) by a given handler,
524 the @nt{choice_parameter_specification}, if any, is first elaborated,
525 which creates the choice parameter and initializes it to the occurrence.
526 Then, the @nt{sequence_of_statements} of the
527 handler is executed;
528 this execution replaces the abandoned portion of the execution of
529 the @nt{sequence_of_statements}.
530 @begin{Ramification}
531 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]}
532 This @lquotes@;replacement@rquotes@; semantics implies that the handler can
533 do pretty much anything the abandoned sequence could do; for example, in a
534 function, the handler can execute a @Chg{Version=[2],New=[return statement],
535 Old=[@nt{return_statement}]} that applies to the function.
536 @end{Ramification}
537 @begin{Ramification}
538 The rules for exceptions raised in library units,
539 main subprograms and partitions follow from the normal rules,
540 plus the semantics of the environment task
541 described in Section 10 (for example, the
542 environment task of a partition elaborates library units and calls
543 the main subprogram).
544 If an exception is propagated by the main subprogram, it is
545 propagated to the environment task, which then terminates abnormally,
546 causing the partition to terminate abnormally.
547 Although abnormal termination of tasks is not necessarily an error,
548 abnormal termination of a partition due to an exception @i{is} an
549 error.
550 @end{Ramification}
551 @end{RunTime}
552
553 @begin{Notes}
554 Note that exceptions raised in a @nt{declarative_part} of a body
555 are not handled by the handlers of the
556 @nt{handled_@!sequence_of_@!statements} of that body.
557 @end{Notes}
558
559 @LabeledSubClause{The Package Exceptions}
560
561 @begin{StaticSem}
562 @leading@keepnext@;The following language-defined library package exists:
563 @begin{Example}
564 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01],ARef=[AI95-00400-01],ARef=[AI95-00438-01]}
565 @ChildUnit{Parent=[Ada],Child=[Exceptions]}@Chg{Version=[2],New=[@key[with] Ada.Streams;
566 ],Old=[]}@key[package] Ada.Exceptions @key[is]@Chg{Version=[2],New=[
567 @key[pragma] Preelaborate(Exceptions);],Old=[]}
568 @key[type] @AdaTypeDefn{Exception_Id} @key[is] @key[private];@Chg{Version=[2],New=[
569 @key[pragma] Preelaborable_Initialization(Exception_Id);],Old=[]}
570 @AdaObjDefn{Null_Id} : @key[constant] Exception_Id;
571 @key[function] @AdaSubDefn{Exception_Name}(Id : Exception_Id) @key[return] String;@Chg{Version=[2],New=[
572 @key[function] @AdaSubDefn{Wide_Exception_Name}(Id : Exception_Id) @key[return] Wide_String;
573 @key[function] @AdaSubDefn{Wide_Wide_Exception_Name}(Id : Exception_Id)
574 @key[return] Wide_Wide_String;],Old=[]}
575
576 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00362-01]}
577 @key[type] @AdaTypeDefn{Exception_Occurrence} @key[is] @key[limited] @key[private];@Chg{Version=[2],New=[
578 @key[pragma] Preelaborable_Initialization(Exception_Occurrence);],Old=[]}
579 @key[type] @AdaTypeDefn{Exception_Occurrence_Access} @key[is] @key[access] @key[all] Exception_Occurrence;
580 @AdaObjDefn{Null_Occurrence} : @key[constant] Exception_Occurrence;
581
582 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00329-01]}
583 @key[procedure] @AdaSubDefn{Raise_Exception}(E : @key[in] Exception_Id;
584 Message : @key[in] String := "");@Chg{Version=[2],New=[
585 @key[pragma] No_Return(Raise_Exception);],Old=[]}
586 @key[function] @AdaSubDefn{Exception_Message}(X : Exception_Occurrence) @key[return] String;
587 @key[procedure] @AdaSubDefn{Reraise_Occurrence}(X : @key[in] Exception_Occurrence);
588
589 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00400-01]}
590 @key[function] @AdaSubDefn{Exception_Identity}(X : Exception_Occurrence)
591 @key[return] Exception_Id;
592 @key[function] @AdaSubDefn{Exception_Name}(X : Exception_Occurrence) @key[return] String;
593 --@RI{ Same as Exception_Name(Exception_Identity(X)).}@Chg{Version=[2],New=[
594 @key[function] @AdaSubDefn{Wide_Exception_Name}(X : Exception_Occurrence)
595 @key[return] Wide_String;
596 --@RI{ Same as Wide_Exception_Name(Exception_Identity(X)).}
597 @key[function] @AdaSubDefn{Wide_Wide_Exception_Name}(X : Exception_Occurrence)
598 @key[return] Wide_Wide_String;
599 --@RI{ Same as Wide_Wide_Exception_Name(Exception_Identity(X)).}],Old=[]}
600 @key[function] @AdaSubDefn{Exception_Information}(X : Exception_Occurrence) @key[return] String;
601
602 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00438-01]}
603 @key[procedure] @AdaSubDefn{Save_Occurrence}(Target : @key[out] Exception_Occurrence;
604 Source : @key[in] Exception_Occurrence);
605 @key[function] @AdaSubDefn{Save_Occurrence}(Source : Exception_Occurrence)
606 @key[return] Exception_Occurrence_Access;@Chg{Version=[2],New=[],Old=[
607 @key[private]
608 ... --@RI{ not specified by the language}
609 @key[end] Ada.Exceptions;]}
610
611 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00438-01]}
612 @ChgAdded{Version=[2],Text=[ @key[procedure] Read_Exception_Occurrence
613 (Stream : @key[not null access] Ada.Streams.Root_Stream_Type'Class;
614 Item : @key[out] Exception_Occurrence);
615 @key[procedure] Write_Exception_Occurrence
616 (Stream : @key[not null access] Ada.Streams.Root_Stream_Type'Class;
617 Item : @key[in] Exception_Occurrence);]}
618
619 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00438-01]}
620 @ChgAdded{Version=[2],Text=[ @key[for] Exception_Occurrence'Read @key[use] Read_Exception_Occurrence;
621 @key[for] Exception_Occurrence'Write @key[use] Write_Exception_Occurrence;]}
622
623 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00438-01]}
624 @ChgAdded{Version=[2],Text=[@key[private]
625 ... --@RI{ not specified by the language}
626 @key[end] Ada.Exceptions;]}
627 @end{Example}
628
629 Each distinct exception is represented by a distinct value
630 of type Exception_Id.
631 Null_Id does not represent any exception,
632 and is the default initial value of type Exception_Id.
633 Each occurrence of an exception is represented by a
634 value of type Exception_Occurrence.
635 Null_Occurrence does not represent any exception occurrence,
636 and is the default initial value of type Exception_Occurrence.
637
638 @ChgRef{Version=[1],Kind=[Revised]}@ChgNote{To be consistent with 8652/0006}
639 @Leading@;For @ChgPrefixType{Version=[1],Kind=[Revised],Text=[a
640 @Chg{New=[@nt{prefix}],Old=[prefix]} E that denotes an exception]},
641 the following attribute is defined:
642 @begin{Description}
643 @Attribute{Prefix=<E>, AttrName=<Identity>,
644 Text=[E'Identity returns the unique identity of the exception.
645 The type of this attribute is Exception_Id.]}
646 @begin{Ramification}
647 In a distributed program,
648 the identity is unique across an entire program,
649 not just across a single partition.
650 Exception propagation works properly across RPC's.
651 An exception can be propagated from one partition to another,
652 and then back to the first, where its identity is known.
653 @end{Ramification}
654 @end{Description}
655
656 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00361-01]}
657 Raise_Exception raises a new occurrence of the identified
658 exception.@Chg{Version=[2],New=[],Old=[ In this case
659 Exception_Message returns the Message parameter of Raise_Exception.
660 For a @nt{raise_statement} with an @i{exception_}@nt{name},
661 Exception_Message returns implementation-defined information
662 about the exception occurrence.
663 Reraise_Occurrence reraises the specified exception occurrence.]}
664
665 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00361-01],ARef=[AI95-00378-01]}
666 @ChgAdded{Version=[2],Text=[Exception_Message returns the message associated
667 with the given Exception_Occurrence. For an occurrence raised by a call to
668 Raise_Exception, the message is the Message parameter passed to Raise_Exception.
669 For the occurrence raised by a @nt{raise_statement} with an
670 @SynI{exception_}@nt{name} and a @SynI{string_}@nt{expression}, the message is
671 the @Syni{string_}@nt{expression}. For the occurrence raised by a
672 @nt{raise_statement} with
673 an @Syni{exception_}@nt{name} but without a @Syni{string_}@nt{expression},
674 the message is a string giving implementation-defined information about the
675 exception occurrence. In all cases, Exception_Message returns a string with
676 lower bound 1.]}
677 @ImplDef{The information returned by Exception_Message.}
678
679 @begin{Ramification}
680 @Leading@Keepnext@;Given an exception E, the @nt{raise_statement}:
681 @begin{Example}
682 @key[raise] E;
683 @end{Example}
684
685 @Leading@keepnext@;is equivalent to this call to Raise_Exception:
686 @begin{Example}
687 Raise_Exception(E'Identity, Message => @RI{implementation-defined-string});
688 @end{Example}
689
690 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00361-01]}
691 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[Similarly, the
692 @nt{raise_statement}:]}
693 @begin{Example}
694 @ChgRef{Version=[2],Kind=[Added]}
695 @ChgAdded{Version=[2],Text=[@key[raise] E @key[with] "some information";]}
696 @end{Example}
697
698 @ChgRef{Version=[2],Kind=[Added]}
699 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[is equivalent to
700 this call to Raise_Exception:]}
701 @begin{Example}
702 @ChgRef{Version=[2],Kind=[Added]}
703 @ChgAdded{Version=[2],Text=[Raise_Exception(E'Identity, Message => "some information");]}
704 @end{Example}
705 @end{Ramification}
706
707 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00361-01]}
708 @ChgAdded{Version=[2],Text=[Reraise_Occurrence reraises the specified exception
709 occurrence.]}
710
711 @begin{Ramification}
712 @Leading@keepnext@;The following handler:
713 @begin{Example}
714 @key[when] @key[others] =>
715 Cleanup;
716 @key[raise];
717 @end{Example}
718
719 @begin{Wide}
720 @Leading@keepnext@;is equivalent to this one:
721 @end{Wide}
722 @begin{Example}
723 @key[when] X : @key[others] =>
724 Cleanup;
725 Reraise_Occurrence(X);
726 @end{Example}
727
728 @end{Ramification}
729
730 Exception_Identity returns the identity of the exception of the
731 occurrence.
732
733 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00400-01]}
734 The @Chg{Version=[2],New=[Wide_@!Wide_@!Exception_Name],Old=[Exception_Name]}
735 functions return
736 the full expanded name of the exception, in upper case, starting with a root
737 library unit. For an exception declared immediately within package Standard,
738 the @nt{defining_@!identifier} is returned.
739 The result is implementation defined if the exception is declared within
740 an unnamed @nt{block_statement}.
741 @begin{Ramification}
742 See the @ImplPermName below.
743 @end{Ramification}
744 @begin{Honest}
745 This name, as well as each @nt{prefix} of it,
746 does not denote a @nt{renaming_declaration}.
747 @end{Honest}
748 @ChgImplDef{Version=[2],Kind=[Revised],Text=[The result of @Chg{Version=[2],
749 New=[Exceptions.@!Wide_@!Wide_@!Exception_@!Name],Old=[Exceptions.@!Exception_@!Name]}
750 for @Chg{Version=[2],New=[exceptions],Old=[types]} declared within
751 an unnamed @nt{block_statement}.]}
752 @begin{Ramification}
753 Note that we're talking about the name of the exception,
754 not the name of the occurrence.
755 @end{Ramification}
756
757 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00400-01]}
758 @ChgAdded{Version=[2],Text=[The Exception_Name functions (respectively,
759 Wide_Exception_Name) return the same sequence of graphic characters as that
760 defined for Wide_Wide_Exception_Name, if all the graphic characters are defined
761 in Character (respectively, Wide_Character); otherwise, the sequence of
762 characters is implementation defined, but no shorter than that returned by
763 Wide_Wide_Exception_Name for the same value of the argument.]}
764 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@Chg{Version=[2],New=[
765 The sequence of characters of the value returned by Exceptions.Exception_Name
766 (respectively, Exceptions.Wide_Exception_Name) when some of the graphic
767 characters of Exceptions.Wide_Wide_Exception_Name are not defined in Character
768 (respectively, Wide_Character).],Old=[]}]}
769
770 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00378-01],ARef=[AI95-00417-01]}
771 @ChgAdded{Version=[2],Text=[The string returned by the Exception_Name,
772 Wide_Exception_Name, and Wide_Wide_Exception_Name functions has lower bound 1.]}
773
774 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00378-01]}
775 Exception_Information returns implementation-defined information
776 about the exception occurrence.
777 @Chg{Version=[2],New=[The returned string has lower bound 1.],Old=[]}
778 @ImplDef{The information returned by Exception_Information.}
779
780 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00241-01],ARef=[AI95-00446-01]}
781 @Chg{Version=[2],New=[],Old=[Raise_Exception and ]}Reraise_Occurrence
782 @Chg{Version=[2],New=[has],Old=[have]} no effect in the case of
783 @Chg{Version=[2],New=[],Old=[Null_Id or ]}Null_Occurrence.
784 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
785 @Chg{Version=[2],New=[Raise_Exception and Exception_Name raise Constraint_Error
786 for a Null_Id. Exception_Message, Exception_Name, and Exception_Information
787 raise Constraint_Error for a Null_Occurrence. Exception_Identity applied
788 to Null_Occurrence returns Null_Id.],
789 Old=[Exception_Message, Exception_Identity, Exception_Name, and
790 Exception_Information
791 raise Constraint_Error for a Null_Id or Null_Occurrence.]}
792
793 @begin{Ramification}
794 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00241-01]}
795 @ChgAdded{Version=[2],Text=[Null_Occurrence can be tested for by comparing
796 Exception_Identity(Occurrence) to Null_Id.]}
797 @end{Ramification}
798
799 @begin{Discussion}
800 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00446-01]}
801 @ChgAdded{Version=[2],Text=[Raise_Exception was changed so that it always
802 raises an exception and thus can be a No_Return procedure. A similar change
803 was not made for Reraise_Occurrence, as doing so was determined to be a
804 significant incompatibility. It is not unusual to pass an Exception_Occurrence
805 to other code to delay raising it. If there was no exception, passing
806 Null_Occurrence works fine (nothing is raised). Moreover, as there is no test
807 for Null_Occurrence in Ada 95, this is the only way to write such code without
808 using additional flags. Breaking this sort of code is unacceptable.]}
809 @end{Discussion}
810
811 The Save_Occurrence procedure copies the Source to the Target.
812 The Save_Occurrence function uses an @nt{allocator} of type
813 Exception_Occurrence_Access to create a new object,
814 copies the Source to this new object,
815 and returns an access value designating this new object;
816 @Redundant[the result may be deallocated using an instance of
817 Unchecked_Deallocation.]
818 @begin{Ramification}
819 It's OK to pass Null_Occurrence to the Save_Occurrence
820 subprograms;
821 they don't raise an exception,
822 but simply save the Null_Occurrence.
823 @end{Ramification}
824
825 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00438-01]}
826 @ChgAdded{Version=[2],Text=[Write_Exception_Occurrence writes a representation
827 of an exception occurrence to a stream; Read_Exception_Occurrence reconstructs
828 an exception occurrence from a stream (including one written in a different
829 partition).]}
830 @ChgNote{All of these notes (except the first) are moved from below.}
831 @begin{Ramification}
832 @ChgRef{Version=[2],Kind=[AddedNormal]}
833 @ChgAdded{Version=[2],Text=[This routines are used to define the stream
834 attributes (see @RefSecNum{Stream-Oriented Attributes}) for
835 Exception_Occurrence.]}
836
837 @ChgRef{Version=[2],Kind=[AddedNormal]}
838 @ChgAdded{Version=[2],Text=[The identity of the exception,
839 as well as the Exception_Name and Exception_Message,
840 have to be preserved across partitions.]}
841
842 @ChgRef{Version=[2],Kind=[AddedNormal]}
843 @ChgAdded{Version=[2],Text=[The string returned by Exception_Name
844 or Exception_Message on the result of calling the Read
845 attribute on a given stream has to be the same as the value returned
846 by calling the corresponding function on the exception occurrence
847 that was written into the stream with the Write attribute.
848 The string returned by Exception_Information need not be
849 the same, since it is implementation defined anyway.]}
850 @end{Ramification}
851 @begin{Reason}
852 @ChgRef{Version=[2],Kind=[AddedNormal]}
853 @ChgAdded{Version=[2],Text=[This is important for supporting writing exception occurrences
854 to external files for post-mortem analysis, as well as
855 propagating exceptions across remote subprogram calls
856 in a distributed system
857 (see @RefSecNum{Remote Subprogram Calls}).]}
858 @end{Reason}
859 @end{StaticSem}
860
861 @begin{ImplReq}
862 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00438-01]}
863 @ChgDeleted{Version=[2],Text=[The implementation of the Write attribute
864 (see @RefSecNum{Stream-Oriented Attributes})
865 of Exception_Occurrence shall support writing
866 a representation of an exception occurrence
867 to a stream; the implementation of the Read attribute
868 of Exception_Occurrence shall support reconstructing
869 an exception occurrence from a stream (including one written in
870 a different partition).]}
871 @begin{Ramification}
872 @ChgRef{Version=[2],Kind=[Deleted]}
873 @ChgDeleted{Version=[2],Text=[The identity of the exception,
874 as well as the Exception_Name and Exception_Message,
875 have to be preserved across partitions.]}
876
877 @ChgRef{Version=[2],Kind=[Deleted]}
878 @ChgDeleted{Version=[2],Text=[The string returned by Exception_Name
879 or Exception_Message on the result of calling the Read
880 attribute on a given stream has to be the same as the value returned
881 by calling the corresponding function on the exception occurrence
882 that was written into the stream with the Write attribute.
883 The string returned by Exception_Information need not be
884 the same, since it is implementation defined anyway.]}
885 @end{Ramification}
886 @begin{Reason}
887 @ChgRef{Version=[2],Kind=[Deleted]}
888 @ChgDeleted{Version=[2],Text=[This is important for supporting writing
889 exception occurrences to external files for post-mortem analysis, as well as
890 propagating exceptions across remote subprogram calls
891 in a distributed system
892 (see @RefSecNum{Remote Subprogram Calls}).]}
893 @end{Reason}
894 @end{ImplReq}
895
896 @begin{ImplPerm}
897 An implementation of Exception_Name in a space-constrained
898 environment may return the
899 @nt{defining_@!identifier} instead of the full expanded name.
900
901
902 The string returned by Exception_Message may be truncated (to no less
903 than 200 characters) by the Save_Occurrence procedure
904 @Redundant[(not the function)],
905 the Reraise_Occurrence procedure,
906 and the re-raise statement.
907 @begin{Reason}
908 The reason for allowing truncation is to ease implementations.
909 The reason for choosing the number 200 is that this is the minimum
910 source line length that implementations have to support,
911 and this feature seems vaguely related since it's usually a
912 @lquotes@;one-liner@rquotes@;.
913 Note that an implementation is allowed to do this truncation even if it
914 supports arbitrarily long lines.
915 @end{Reason}
916 @end{ImplPerm}
917
918 @begin{ImplAdvice}
919 Exception_Message (by default) and Exception_Information should produce
920 information useful for debugging.
921 Exception_Message should be short (about one line),
922 whereas Exception_Information can be long.
923 Exception_Message should not include the Exception_Name.
924 Exception_Information should include both the Exception_Name and the
925 Exception_Message.
926 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
927 Text=[Exception_Information should provide
928 information useful for debugging, and should include the Exception_Name
929 and Exception_Message.]}]}
930 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
931 Text=[Exception_Message by default should be short, provide
932 information useful for debugging, and should not include the Exception_Name.]}]}
933
934 @begin{Reason}
935 It may seem strange to define two subprograms whose semantics is
936 implementation defined.
937 The idea is that a program can print out debugging/error-logging
938 information in a portable way.
939 The program is portable in the sense that it will work in any
940 implementation; it might print out different information, but the
941 presumption is that the information printed out is appropriate for
942 debugging/error analysis on that system.
943 @end{Reason}
944 @begin{ImplNote}
945 As an example, Exception_Information might include
946 information identifying the location where the exception
947 occurred, and, for predefined exceptions, the specific kind of
948 language-defined check that failed.
949 There is an implementation trade-off here, between how much
950 information is represented in an Exception_Occurrence, and how much
951 can be passed through a re-raise.
952
953 The string returned should be in a form suitable for printing to an
954 error log file.
955 This means that it might need to contain line-termination control
956 characters with implementation-defined I/O semantics.
957 The string should neither start nor end with a newline.
958
959 If an implementation chooses to provide additional functionality
960 related to exceptions and their occurrences,
961 it should do so by providing one or more children of
962 Ada.Exceptions.
963
964 Note that exceptions behave as if declared at library level;
965 there is no @lquotes@;natural scope@rquotes@; for an exception; an exception always
966 exists. Hence, there is no harm in saving an exception occurrence in
967 a data structure, and reraising it later. The reraise has to occur
968 as part of the same program execution, so saving an exception
969 occurrence in a file, reading it back in from a different
970 program execution, and then reraising it is not required to work.
971 This is similar to I/O of access types.
972 Note that it is possible to use RPC to propagate exceptions across
973 partitions.
974
975 @Leading@;Here's one way to implement Exception_Occurrence in the private part
976 of the package. Using this method, an implementation need store only
977 the actual number of characters in exception messages. If the user
978 always uses small messages, then exception occurrences can be small.
979 If the user never uses messages, then exception occurrences can be
980 smaller still:
981 @begin{Example}
982 @key[type] Exception_Occurrence(Message_Length : Natural := 200) @key[is]
983 @key[limited] @key[record]
984 Id : Exception_Id;
985 Message : String(1..Message_Length);
986 @key[end] @key[record];
987 @end{Example}
988
989 @Leading@;At the point where an exception is raised, an Exception_Occurrence
990 can be allocated on the stack with exactly the right amount of space
991 for the message @em none for an empty message. This is just like
992 declaring a constrained object of the type:
993 @begin{Example}
994 Temp : Exception_Occurrence(10); --@RI{ for a 10-character message}
995 @end{Example}
996
997 After finding the appropriate handler, the stack can be cut back,
998 and the Temp copied to the right place. This is similar to returning
999 an unknown-sized object from a function. It is not necessary to
1000 allocate the maximum possible size for every Exception_Occurrence.
1001 If, however, the user declares an Exception_Occurrence object,
1002 the discriminant will be permanently set to 200. The Save_Occurrence
1003 procedure would then truncate the Exception_Message. Thus, nothing is
1004 lost until the user tries to save the occurrence. If the user is
1005 willing to pay the cost of heap allocation, the Save_Occurrence
1006 function can be used instead.
1007
1008 Note that any arbitrary-sized implementation-defined Exception_Information can
1009 be handled in a similar way. For example, if the
1010 Exception_Occurrence includes a stack traceback, a discriminant can
1011 control the number of stack frames stored. The traceback would be
1012 truncated or entirely deleted by the Save_Occurrence procedure @em as
1013 the implementation sees fit.
1014
1015 If the internal representation involves pointers to data structures
1016 that might disappear, it would behoove the implementation to
1017 implement it as a controlled type,
1018 so that assignment can either copy the data structures or else null
1019 out the pointers.
1020 Alternatively, if the data structures being pointed at are in a
1021 task control block,
1022 the implementation could keep a unique sequence number
1023 for each task, so it could tell when a task's data structures no longer
1024 exist.
1025
1026 Using the above method, heap space is never allocated unless the user
1027 calls the Save_Occurrence function.
1028
1029 @Leading@;An alternative implementation would be to store the message strings
1030 on the heap when the exception is raised. (It could be the global
1031 heap, or it could be a special heap just for this purpose @em it
1032 doesn't matter.) This representation would be used only for choice
1033 parameters. For normal user-defined exception occurrences, the
1034 Save_Occurrence procedure would copy the message string into the
1035 occurrence itself, truncating as necessary. Thus, in this
1036 implementation, Exception_Occurrence would be implemented as a
1037 variant record:
1038 @begin{Example}
1039 @key[type] Exception_Occurrence_Kind @key[is] (Normal, As_Choice_Param);
1040
1041 @key[type] Exception_Occurrence(Kind : Exception_Occurrence_Kind := Normal) @key[is]
1042 @key[limited] @key[record]
1043 @key[case] Kind @key[is]
1044 @key[when] Normal =>
1045 ... --@RI{ space for 200 characters}
1046 @key[when] As_Choice_Param =>
1047 ... --@RI{ pointer to heap string}
1048 @key[end] @key[case];
1049 @key[end] @key[record];
1050 @end{Example}
1051
1052 Exception_Occurrences created by the run-time system during exception
1053 raising would be As_Choice_Param. User-declared ones would be Normal @em the
1054 user cannot see the discriminant, and so cannot set it to As_Choice_Param.
1055 The strings in the heap would be freed upon completion of the
1056 handler.
1057
1058 This alternative implementation corresponds to a heap-based
1059 implementation of functions returning unknown-sized results.
1060
1061 @Leading@;One possible implementation of Reraise_Occurrence is as follows:
1062 @begin{Example}
1063 @key[procedure] Reraise_Occurrence(X : @key[in] Exception_Occurrence) @key[is]
1064 @key[begin]
1065 Raise_Exception(Identity(X), Exception_Message(X));
1066 @key[end] Reraise_Occurrence;
1067 @end{Example}
1068
1069 However, some implementations may wish to retain more information
1070 across a re-raise @em a stack traceback, for example.
1071 @end{ImplNote}
1072 @begin{Ramification}
1073 Note that Exception_Occurrence is a definite subtype.
1074 Hence, values of type Exception_Occurrence may be written to
1075 an error log for later analysis, or may be passed
1076 to subprograms for immediate error analysis.
1077 @end{Ramification}
1078 @begin{ImplNote}
1079 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00400-01]}
1080 @ChgDeleted{Version=[2],Text=[If an implementation chooses to have a mode in
1081 which it supports non-Latin-1 characters in identifiers, then it needs to
1082 define what the above functions return in the case where the name of an
1083 exception contains such a character.]}
1084 @end{ImplNote}
1085 @end{ImplAdvice}
1086
1087 @begin{Extend83}
1088 @Defn{extensions to Ada 83}
1089 The Identity attribute of exceptions is new, as is the package
1090 Exceptions.
1091 @end{Extend83}
1092
1093 @begin{Inconsistent95}
1094 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00241-01]}
1095 @ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95}
1096 @B[Amendment Correction:] Exception_Identity of an Exception_Occurrence
1097 now is defined to return Null_Id for Null_Occurrence, rather than raising
1098 Constraint_Error. This provides a simple way to test for Null_Occurrence.
1099 We expect that programs that need Constraint_Error raised will be very rare;
1100 they can be easily fixed by explicitly testing for Null_Id or by using
1101 Exception_Name instead.]}
1102
1103 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00378-01],ARef=[AI95-00417-01]}
1104 @ChgAdded{Version=[2],Text=<@B[Amendment Correction:] We now define the lower
1105 bound of the string returned from [[Wide_]Wide_]Exception_Name,
1106 Exception_Message, and Exception_Information. This makes working with the
1107 returned string easier, and is consistent with many other string-returning
1108 functions in Ada. This is technically an inconsistency; if a program
1109 depended on some other lower bound for the string returned from one of
1110 these functions, it could fail when compiled with Ada 2005. Such code is
1111 not portable even between Ada 95 implementations, so it should be very rare.>}
1112
1113 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00446-01]}
1114 @ChgAdded{Version=[2],Text=[@B[Amendment Correction:]
1115 Raise_Exception now raises Constraint_Error if passed Null_Id. This means
1116 that it always raises an exception, and thus we can apply pragma No_Return to
1117 it. We expect that programs that call Raise_Exception with Null_Id will be
1118 rare, and programs that do that and expect no exception to be raised will be
1119 rarer; such programs can be easily fixed by explicitly testing for Null_Id
1120 before calling Raise_Exception.]}
1121 @end{Inconsistent95}
1122
1123 @begin{Incompatible95}
1124 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00400-01],ARef=[AI95-00438-01]}
1125 @ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95}
1126 Functions Wide_Exception_Name and Wide_Wide_Exception_Name, and procedures
1127 Read_Exception_Occurrence and Write_Exception_Occurrence
1128 are newly added to Exceptions. If Exceptions is referenced in a
1129 @nt{use_clause}, and an entity @i<E> with the same @nt{defining_identifier}
1130 as a new entity in Exceptions is defined in a
1131 package that is also referenced in a @nt{use_clause}, the entity @i<E> may no
1132 longer be use-visible, resulting in errors. This should be rare and is easily
1133 fixed if it does occur.]}
1134 @end{Incompatible95}
1135
1136 @begin{Extend95}
1137 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00362-01]}
1138 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1139 The package Exceptions is preelaborated, and types Exception_Id and
1140 Exception_Occurrence have preelaborable initialization, allowing this package
1141 to be used in preelaborated units.]}
1142 @end{Extend95}
1143
1144 @begin{DiffWord95}
1145 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00361-01]}
1146 @ChgAdded{Version=[2],Text=[The meaning of Exception_Message is reworded to
1147 reflect that the string can come from a @nt{raise_statement} as well as a
1148 call of Raise_Exception.]}
1149
1150 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00400-01]}
1151 @ChgAdded{Version=[2],Text=[Added Wide_Exception_Name and
1152 Wide_Wide_Exception_Name
1153 because identifiers can now contain characters outside of Latin-1.]}
1154 @end{DiffWord95}
1155
1156
1157 @LabeledAddedSubClause{Version=[2],Name=[Pragmas Assert and Assertion_Policy]}
1158
1159 @begin{Intro}
1160 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1161 @ChgAdded{Version=[2],Text=[Pragma Assert is used to assert the truth of a
1162 Boolean expression at any point within a sequence of declarations or statements.
1163 Pragma Assertion_Policy is used to control whether such assertions@Defn{Assertions}
1164 are to be ignored by the implementation, checked at run-time, or handled in
1165 some implementation-defined manner.]}
1166 @end{Intro}
1167
1168 @begin{Syntax}
1169 @begin{SyntaxText}
1170 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1171 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[The form of a
1172 @nt{pragma} Assert is as follows:]}
1173 @end{SyntaxText}
1174
1175 @ChgRef{Version=[2],Kind=[AddedNormal]}
1176 @ChgAdded{Version=[2],Text=`@AddedPragmaSyn`Version=[2],@key{pragma} @prag<Assert>([Check =>] @SynI{boolean_}@Syn2{expression}[, [Message =>] @SynI{string_}@Syn2{expression}]);''}
1177
1178 @begin{SyntaxText}
1179 @ChgRef{Version=[2],Kind=[AddedNormal]}
1180 @ChgAdded{Version=[2],Text=[A @nt{pragma} Assert is allowed at the place where a
1181 @nt{declarative_item} or a @nt{statement} is allowed.]}
1182
1183 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1184 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[The form of a
1185 @nt{pragma} Assertion_Policy is as follows:]}
1186 @end{SyntaxText}
1187
1188 @ChgRef{Version=[2],Kind=[AddedNormal]}
1189 @ChgAdded{Version=[2],Text=<@AddedPragmaSyn`Version=[2],@key{pragma} @prag<Assertion_Policy>(@SynI{policy_}@Syn2{identifier});'>}
1190
1191 @ChgRef{Version=[2],Kind=[AddedNormal]}
1192 @ChgAdded{Version=[2],Text=[@PDefn2{Term=[configuration pragma], Sec=(Assertion_Policy)}
1193 @PDefn2{Term=[pragma, configuration], Sec=(Assertion_Policy)}
1194 A @nt{pragma} Assertion_Policy is a configuration pragma.]}
1195
1196 @end{Syntax}
1197
1198 @begin{Resolution}
1199 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1200 @ChgAdded{Version=[2],Text=[The expected type for the
1201 @Syni{boolean_}@nt{expression} of a @nt{pragma} Assert
1202 is any boolean type. The expected type for the @Syni{string_}@nt{expression}
1203 of a @nt{pragma} Assert is type String.]}
1204 @begin{Reason}
1205 @ChgRef{Version=[2],Kind=[AddedNormal]}
1206 @ChgAdded{Version=[2],Text=[We allow any boolean type to be like
1207 @nt{if_statement}s and other conditionals; we only allow String for the
1208 message in order to match @nt{raise_statement}s.]}
1209 @end{Reason}
1210 @end{Resolution}
1211
1212
1213 @begin{Legality}
1214 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1215 @ChgAdded{Version=[2],Text=[The @SynI<policy_>@nt<identifier> of a @nt{pragma}
1216 Assertion_Policy shall be either Check, Ignore, or an implementation-defined
1217 identifier.]}
1218 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@Chg{Version=[2],New=[Implementation-defined
1219 @SynI<policy_>@nt<identifier>s allowed in a @nt{pragma} Assertion_Policy.],Old=[]}]}
1220 @end{Legality}
1221
1222 @begin{StaticSem}
1223 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1224 @ChgAdded{Version=[2],Text=[A @nt<pragma> Assertion_Policy is a configuration pragma
1225 that specifies the assertion policy in effect for the compilation units to which it
1226 applies. Different policies may apply to different compilation
1227 units within the same partition. The default assertion policy is
1228 implementation-defined.]}
1229 @ChgImplDef{Version=[2],Kind=[AddedNormal],Text=[@Chg{Version=[2],New=[The
1230 default assertion policy.],Old=[]}]}
1231
1232 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1233 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[The following
1234 language-defined library package exists:]}
1235
1236 @begin{Example}
1237 @ChgRef{Version=[2],Kind=[AddedNormal]}
1238 @ChgAdded{Version=[2],Text=[@ChildUnit{Parent=[Ada],Child=[Assertions]}@key[package] Ada.Assertions @key[is]
1239 @key[pragma] Pure(Assertions);]}
1240
1241 @ChgRef{Version=[2],Kind=[AddedNormal]}
1242 @ChgAdded{Version=[2],Text=[ Assertion_Error : @key<exception>;]}
1243
1244 @ChgRef{Version=[2],Kind=[AddedNormal]}
1245 @ChgAdded{Version=[2],Text=[ @key<procedure> Assert(Check : @key<in> Boolean);
1246 @key<procedure> Assert(Check : @key<in> Boolean; Message : @key<in> String);]}
1247
1248 @ChgRef{Version=[2],Kind=[AddedNormal]}
1249 @ChgAdded{Version=[2],Text=[@key<end> Ada.Assertions;]}
1250 @end{Example}
1251
1252 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1253 @ChgAdded{Version=[2],Text=[A compilation unit containing a @nt{pragma} Assert has a
1254 semantic dependence on the Assertions library unit.]}
1255
1256 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1257 @ChgAdded{Version=[2],Text=[The assertion policy that applies to a generic unit
1258 also applies to all its instances.]}
1259 @end{StaticSem}
1260
1261
1262 @begin{RunTime}
1263 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1264 @ChgAdded{Version=[2],Text=[An assertion policy @defn{assertion policy}specifies
1265 how a @nt{pragma} Assert is interpreted by the implementation. If the assertion
1266 policy is Ignore at the point of a @nt{pragma} Assert, the pragma is ignored.
1267 If the assertion policy is Check at the point of a @nt{pragma} Assert, the
1268 elaboration of the pragma consists of evaluating the boolean expression, and if
1269 the result is False, evaluating the Message argument, if any, and raising the
1270 exception Assertions.Assertion_Error, with a message if the Message
1271 argument is provided.]}
1272
1273 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1274 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[Calling the procedure
1275 Assertions.Assert without a Message parameter is equivalent to:]}
1276
1277 @begin{Example}
1278 @ChgRef{Version=[2],Kind=[AddedNormal]}
1279 @ChgAdded{Version=[2],Text=[@key<if> Check = False @key<then>
1280 @key<raise> Ada.Assertions.Assertion_Error;
1281 @key{end} @key{if};]}
1282 @end{Example}
1283
1284 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1285 @ChgAdded{Version=[2],Type=[Leading],Keepnext=[T],Text=[Calling the procedure
1286 Assertions.Assert with a Message parameter is equivalent to:]}
1287
1288 @begin{Example}
1289 @ChgRef{Version=[2],Kind=[AddedNormal]}
1290 @ChgAdded{Version=[2],Text=[@key<if> Check = False @key<then>
1291 @key<raise> Ada.Assertions.Assertion_Error @key<with> Message;
1292 @key{end} @key{if};]}
1293 @end{Example}
1294
1295 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1296 @ChgAdded{Version=[2],Text=[The procedures Assertions.Assert have these
1297 effects independently of the assertion policy in effect.]}
1298
1299 @end{RunTime}
1300
1301 @begin{ImplPerm}
1302 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1303 @ChgAdded{Version=[2],Text=[Assertion_Error may be declared by renaming an
1304 implementation-defined exception from another package.]}
1305 @begin{Reason}
1306 @ChgRef{Version=[2],Kind=[AddedNormal]}
1307 @ChgAdded{Version=[2],Text=[This permission is intended to allow implementations
1308 which had an implementation-defined Assert pragma to continue to use their
1309 originally defined exception. Without this permission, such an implementation
1310 would be incorrect, as Exception_Name would return the wrong name.]}
1311 @end{Reason}
1312 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1313 @ChgAdded{Version=[2],Text=[Implementations may define their own assertion policies.]}
1314 @end{ImplPerm}
1315
1316 @begin{Notes}
1317 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1318 @ChgAdded{Version=[2],Text=[Normally, the boolean expression in a @nt{pragma}
1319 Assert should not call functions that have significant side-effects when the
1320 result of the expression is True, so that the particular assertion policy in
1321 effect will not affect normal operation of the program.]}
1322 @end{Notes}
1323
1324 @begin{Extend95}
1325 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00286-01]}
1326 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}
1327 Pragmas Assert and Assertion_Policy, and package Assertions are new.]}
1328 @end{Extend95}
1329
1330 @LabeledSubClause{Example of Exception Handling}
1331
1332 @begin{Examples}
1333 @Leading@;Exception handling may be used to separate the detection of an error
1334 from the response to that error:
1335 @begin{Example}
1336 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
1337 @Chg{Version=[2],New=[],Old=[@key[with] Ada.Exceptions;
1338 @key[use] Ada;
1339 ]}@key[package] File_System @key[is]
1340 @key[type] File_Handle @key[is] @key[limited] @key[private];
1341
1342 File_Not_Found : @key[exception];
1343 @key[procedure] Open(F : @key[in] @key[out] File_Handle; Name : String);
1344 --@RI{ raises File_Not_Found if named file does not exist}
1345
1346 End_Of_File : @key[exception];
1347 @key[procedure] Read(F : @key[in] @key[out] File_Handle; Data : @key[out] Data_Type);
1348 --@RI{ raises End_Of_File if the file is not open}
1349
1350 ...
1351 @key[end] File_System;
1352
1353
1354 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00433-01]}
1355 @key[package] @key[body] File_System @key[is]
1356 @key[procedure] Open(F : @key[in] @key[out] File_Handle; Name : String) @key[is]
1357 @key[begin]
1358 @key[if] File_Exists(Name) @key[then]
1359 ...
1360 @key[else]
1361 @Chg{Version=[2],New=[@key[raise] ],Old=[Exceptions.Raise_Exception(]}File_Not_Found@Chg{Version=[2],New=[ @key[with] ],Old=['Identity,
1362 ]}"File not found: " & Name & "."@Chg{Version=[2],New=[],Old=[)]};
1363 @key[end] @key[if];
1364 @key[end] Open;
1365
1366 @key[procedure] Read(F : @key[in] @key[out] File_Handle; Data : @key[out] Data_Type) @key[is]
1367 @key[begin]
1368 @key[if] F.Current_Position <= F.Last_Position @key[then]
1369 ...
1370 @key[else]
1371 @key[raise] End_Of_File;
1372 @key[end] @key[if];
1373 @key[end] Read;
1374
1375 ...
1376
1377 @key[end] File_System;
1378
1379
1380 @key[with] Ada.Text_IO;
1381 @key[with] Ada.Exceptions;
1382 @key[with] File_System; @key[use] File_System;
1383 @key[use] Ada;
1384 @key[procedure] Main @key[is]
1385 @key[begin]
1386 ... --@RI{ call operations in File_System}
1387 @key[exception]
1388 @key[when] End_Of_File =>
1389 Close(Some_File);
1390 @key[when] Not_Found_Error : File_Not_Found =>
1391 Text_IO.Put_Line(Exceptions.Exception_Message(Not_Found_Error));
1392 @key[when] The_Error : @key[others] =>
1393 Text_IO.Put_Line("Unknown error:");
1394 @key[if] Verbosity_Desired @key[then]
1395 Text_IO.Put_Line(Exceptions.Exception_Information(The_Error));
1396 @key[else]
1397 Text_IO.Put_Line(Exceptions.Exception_Name(The_Error));
1398 Text_IO.Put_Line(Exceptions.Exception_Message(The_Error));
1399 @key[end] @key[if];
1400 @key[raise];
1401 @key[end] Main;
1402 @end{Example}
1403
1404
1405 In the above example, the File_System package contains information about
1406 detecting certain exceptional situations,
1407 but it does not specify how to handle those situations.
1408 Procedure Main specifies how to handle them;
1409 other clients of File_System might have different handlers,
1410 even though the exceptional situations arise from the same basic causes.
1411 @end{Examples}
1412
1413 @begin{DiffWord83}
1414 The sections labeled @lquotes@;Exceptions Raised During ...@rquotes@;
1415 are subsumed by this clause,
1416 and by parts of Section 9.
1417 @end{DiffWord83}
1418
1419 @LabeledClause{Suppressing Checks}
1420
1421 @begin{Intro}
1422 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1423 @Chg{Version=[2],New=[@i{Checking pragmas}@Defn{Checking pragmas} give
1424 instructions to an implementation on handling language-defined checks.],Old=[]}
1425 A @nt{pragma} Suppress gives permission to an
1426 implementation to omit certain language-defined checks@Chg{Version=[2],
1427 New=[, while a @nt<pragma> Unsuppress revokes the permission to omit checks.],Old=[]}.
1428
1429 @Defn{language-defined check}
1430 @Defn2{Term=[check], Sec=(language-defined)}
1431 @IndexSee{Term=[run-time check],See=(language-defined check)}
1432 @Defn{run-time error}
1433 @Defn2{Term=[error], Sec=(run-time)}
1434 A @i{language-defined check} (or simply, a @lquotes@;check@rquotes@;) is
1435 one of the situations defined by this International Standard that requires a check to
1436 be made at run time to determine whether some
1437 condition is true.
1438 @Defn2{Term=[failure],Sec=(of a language-defined check)}
1439 A check @i{fails} when the condition being checked is false,
1440 causing an exception to be raised.
1441 @begin{Discussion}
1442 All such checks are defined under @lquotes@;@RunTimeTitle@rquotes@;
1443 in clauses and subclauses throughout the standard.
1444 @end{Discussion}
1445 @end{Intro}
1446
1447 @begin{Syntax}
1448 @begin{SyntaxText}
1449 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1450 @Leading@Keepnext@;The form@Chg{Version=[2],New=[s of checking pragmas are],Old=[ of a @nt{pragma} Suppress is]} as follows:
1451 @end{SyntaxText}
1452
1453 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1454 @PragmaSyn`@key{pragma} @prag(Suppress)(@Syn2{identifier}@Chg{Version=[2],New=<>,Old=( [, [On =>] @Syn2{name}])});'
1455
1456 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00224-01]}
1457 @ChgAdded{Version=[2],Text=<@AddedPragmaSyn`Version=[2],@key{pragma} @prag(Unsuppress)(@Syn2{identifier});'>}
1458
1459 @begin{SyntaxText}
1460 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1461 @PDefn2{Term=[configuration pragma], Sec=(Suppress)}
1462 @PDefn2{Term=[pragma, configuration], Sec=(Suppress)}
1463 @Chg{Version=[2],New=[@PDefn2{Term=[configuration pragma], Sec=(Unsuppress)}
1464 @PDefn2{Term=[pragma, configuration], Sec=(Unsuppress)}],Old=[]}
1465 A @Chg{Version=[2],New=<checking pragma>,Old=<@nt{pragma} Suppress>} is
1466 allowed only immediately within a
1467 @nt{declarative_part}, immediately within a @nt{package_@!specification},
1468 or as a configuration pragma.
1469 @end{SyntaxText}
1470 @end{Syntax}
1471
1472 @begin{Legality}
1473 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1474 The @nt{identifier} shall be the name of a check.
1475 @Chg{Version=[2],New=<>,Old=<The @nt{name} (if present) shall statically denote
1476 some entity.>}
1477
1478 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00224-01]}
1479 @ChgDeleted{Version=[2],Text=<For a @nt{pragma} Suppress that is immediately
1480 within a @nt{package_specification} and includes a @nt<name>, the @nt<name>
1481 shall denote an entity (or several overloaded subprograms) declared immediately
1482 within the @nt{package_specification}.>}
1483 @end{Legality}
1484
1485 @begin{StaticSem}
1486 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00224-01]}
1487 @ChgAdded{Version=[2],Text=[A checking pragma applies to the named check in a
1488 specific region,
1489 and applies to all entities in that region. A checking pragma given in a
1490 @nt<declarative_part> or immediately within a @nt<package_specification>
1491 applies from the place of the @nt<pragma> to the end of the innermost enclosing
1492 declarative region. The region for a checking pragma given as a configuration
1493 pragma is the declarative region for the entire compilation unit (or units) to
1494 which it applies.]}
1495
1496 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00224-01]}
1497 @ChgAdded{Version=[2],Text=[If a checking pragma applies to a generic instantiation, then the checking
1498 pragma also applies to the instance. If a checking pragma applies to a call to
1499 a subprogram that has a @nt<pragma> Inline applied to it, then the checking
1500 pragma also applies to the inlined subprogram body.]}
1501
1502 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1503 A @nt{pragma} Suppress gives permission to an implementation to omit the
1504 named check @Chg{Version=[2],New=[(or every check in the case of All_Checks) for any entities to which it
1505 applies.],Old=[from the place of the @nt{pragma} to the end of the
1506 innermost enclosing declarative region, or,
1507 if the @nt{pragma} is given in a @nt{package_@!specification}
1508 and includes a @nt<name>,
1509 to the end of the scope of the named entity.
1510 If the @nt{pragma} includes a @nt{name},
1511 the permission applies only to checks performed on the named entity,
1512 or, for a subtype, on objects and values of its type.
1513 Otherwise, the permission applies to all entities.]}
1514 @Defn{suppressed check}
1515 If permission has been given to suppress a given check,
1516 the check is said to be @i{suppressed}.
1517 @begin{Ramification}
1518 A check is suppressed even if the implementation chooses not to
1519 actually generate better code.
1520 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
1521 This allows the implementation to raise Program_Error,
1522 for example, if the erroneousness is detected.
1523 @end{Ramification}
1524
1525 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00224-01]}
1526 @ChgAdded{Version=[2],Text=[A @nt{pragma} Unsuppress revokes the permission
1527 to omit the named check (or every check in the case of All_Checks) given by any
1528 @nt{pragma} Suppress that applies at the point of the @nt{pragma} Unsuppress.
1529 The permission is revoked for the region to which the @nt{pragma} Unsuppress
1530 applies. If there is no such permission at the point of a @nt{pragma}
1531 Unsuppress, then the @nt{pragma} has no effect. A later @nt{pragma} Suppress
1532 can renew the permission.]}
1533
1534 @Leading@Keepnext@;The following are the language-defined checks:
1535 @begin{Itemize}
1536 @Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)}
1537 @Leading@Redundant[The following checks correspond to situations in which the
1538 exception Constraint_Error is raised upon failure.]
1539 @begin{Description}
1540 @ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0036],ARef=[AI95-00176-01]}
1541 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]}
1542 @RootDefn{Access_Check}
1543 Access_Check @\@Redundant[When evaluating a dereference (explicit
1544 or implicit),
1545 check that the value of the @nt{name} is not @key{null}.
1546 @Chg{Version=[2],New=[When converting to a subtype that excludes null,
1547 check that the converted value is not @key{null}.],
1548 Old=[When passing an actual parameter to a formal access parameter,
1549 check that the value of the actual parameter is not @key{null}.
1550 @Chg{Version=[1],New=[When evaluating a @nt{discriminant_association} for an
1551 access discriminant, check that the value of the discriminant is not @key{null}.],
1552 Old=[]}]}]
1553
1554 @RootDefn{Discriminant_Check}
1555 Discriminant_Check @\@Redundant[Check that the discriminants of a
1556 composite value
1557 have the values imposed by a discriminant constraint. Also, when
1558 accessing a record component, check that it exists for the current
1559 discriminant values.]
1560
1561 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00434-01]}
1562 @RootDefn{Division_Check}
1563 Division_Check @\@Redundant[Check that the second operand is not zero
1564 for the
1565 operations /, @Chg{Version=[2],New=[@key[rem]],Old=[rem]} and
1566 @Chg{Version=[2],New=[@key[mod]],Old=[mod]}.]
1567
1568 @RootDefn{Index_Check}
1569 Index_Check @\@Redundant[Check that the bounds of an array value are
1570 equal to the
1571 corresponding bounds of an index constraint. Also, when accessing a
1572 component of an array object, check for each dimension that the given
1573 index value belongs to the range defined by the bounds of the array
1574 object. Also, when accessing a slice of an array object, check that
1575 the given discrete range is compatible with the range defined by the
1576 bounds of the array object.]
1577
1578 @RootDefn{Length_Check}
1579 Length_Check @\@Redundant[Check that two arrays have matching
1580 components,
1581 in the case of array subtype conversions,
1582 and logical operators for arrays of boolean components.]
1583
1584 @RootDefn{Overflow_Check}
1585 Overflow_Check @\@Redundant[Check that a scalar value is within the
1586 base range of
1587 its type, in cases where the implementation chooses to raise an
1588 exception instead of returning the correct mathematical result.]
1589
1590 @RootDefn{Range_Check}
1591 Range_Check @\@Redundant[Check that a scalar value satisfies a range
1592 constraint.
1593 Also, for the elaboration of a @nt<subtype_indication>, check that
1594 the @nt<constraint> (if present) is compatible with the
1595 subtype denoted by the @nt{subtype_mark}.
1596 Also, for an @nt<aggregate>, check that an index or
1597 discriminant value belongs to the corresponding subtype. Also, check
1598 that when the result of an operation yields an array, the value of
1599 each component belongs to the component subtype.]
1600
1601 @RootDefn{Tag_Check}
1602 Tag_Check @\@Redundant[Check that operand tags in a dispatching call
1603 are all equal.
1604 Check for the correct tag on tagged type conversions,
1605 for an @nt{assignment_statement},
1606 and when returning a tagged limited object from a function.]
1607 @end{Description}
1608
1609 @Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}
1610 @Leading@Redundant[The following checks correspond to situations in which the
1611 exception Program_Error is raised upon failure.]
1612 @begin{Description}
1613 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00280]}
1614 @ChgAdded{Version=[2],Text=[@RootDefn{Accessibility_Check}
1615 Accessibility_Check @\@Redundant[Check the accessibility level of an
1616 entity or view.]]}
1617
1618 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00280]}
1619 @ChgAdded{Version=[2],Text=[@RootDefn{Allocation_Check}
1620 Allocation_Check @\@Redundant[For an @nt<allocator>, check that the master of
1621 any tasks to be created by the @nt{allocator} is not yet completed or some
1622 dependents have not yet terminated, and that the finalization of the
1623 collection has not started.]]}
1624
1625 @RootDefn{Elaboration_Check}
1626 Elaboration_Check @\@Redundant[When a subprogram or protected entry is
1627 called, a task activation is accomplished,
1628 or a generic instantiation is elaborated, check that the body
1629 of the corresponding unit has already been elaborated.]
1630
1631 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00280]}
1632 @ChgNote{This item is not in alphabetical order}
1633 @ChgDeleted{Version=[2],Text=[@RootDefn{Accessibility_Check}
1634 Accessibility_Check @\@Redundant[Check the accessibility level of an
1635 entity or view.]]}
1636
1637 @end{Description}
1638
1639 @Leading@Redundant[The following check corresponds to situations in which the
1640 exception Storage_Error is raised upon failure.]
1641 @begin{Description}
1642 @RootDefn{Storage_Check}
1643 @Defn2{Term=[Storage_Error],Sec=(raised by failure of run-time check)}
1644 Storage_Check @\@Redundant[Check that evaluation of an @nt{allocator}
1645 does not require
1646 more space than is available for a storage pool. Check
1647 that the space available for a task or subprogram has
1648 not been exceeded.]
1649 @begin{Reason}
1650 We considered splitting this out into three categories:
1651 Pool_Check (for @nt{allocator}s), Stack_Check (for stack usage),
1652 and Heap_Check (for implicit use of the heap @em use of the heap
1653 other than through an @nt{allocator}).
1654 Storage_Check would then represent the union of these three.
1655 However, there seems to be no compelling reason to do this,
1656 given that it is not feasible to split Storage_Error.
1657 @end{Reason}
1658 @end{Description}
1659
1660 @Leading@Redundant[The following check corresponds to all situations in which
1661 any predefined exception is raised.]
1662 @begin{Description}
1663 @RootDefn{All_Checks}
1664 All_Checks @\Represents the union of all checks;
1665 @Redundant[suppressing All_Checks suppresses all checks.]
1666 @begin{Ramification}
1667 All_Checks includes both language-defined and implementation-defined
1668 checks.
1669 @end{Ramification}
1670 @end{Description}
1671 @end{Itemize}
1672 @end{StaticSem}
1673
1674 @begin{Erron}
1675 @PDefn2{Term=(erroneous execution),Sec=(cause)}
1676 If a given check has been suppressed,
1677 and the corresponding error situation occurs,
1678 the execution of the program is erroneous.
1679 @end{Erron}
1680
1681 @begin{ImplPerm}
1682 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1683 An implementation is allowed to place restrictions on
1684 @Chg{Version=[2],New=[checking pragmas, subject only to the requirement that
1685 @nt{pragma} Unsuppress shall allow any
1686 check names supported by @nt{pragma} Suppress],Old=[Suppress @nt<pragma>s]}.
1687 An implementation is allowed to add additional check names,
1688 with implementation-defined semantics.
1689 @PDefn{unspecified}
1690 When Overflow_Check has been suppressed,
1691 an implementation may also suppress an unspecified
1692 subset of the Range_Checks.
1693 @begin{Reason}
1694 @ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00224-01]}
1695 @ChgDeleted{Version=[2],Text=[The permission to restrict is given
1696 so the implementation can give an error message when the
1697 requested suppression is nonsense, such as suppressing a Range_Check
1698 on a task type.
1699 It would be verbose and pointless to list all the cases of
1700 nonsensical language-defined checks in the standard,
1701 and since the list of checks is open-ended,
1702 we can't list the restrictions for implementation-defined checks
1703 anyway.]}
1704 @end{Reason}
1705 @ImplDef{Implementation-defined check names.}
1706 @begin{Discussion}
1707 For Overflow_Check, the intention is that the
1708 implementation will suppress any Range_Checks that are implemented in
1709 the same manner as Overflow_Checks (unless they are free).
1710 @end{Discussion}
1711
1712 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00224-01]}
1713 @ChgAdded{Version=[2],Text=[An implementation may support an additional
1714 parameter on
1715 @nt{pragma} Unsuppress similar to the one allowed for @nt{pragma} Suppress
1716 (see @RefSecNum{Specific Suppression of Checks}). The meaning of
1717 such a parameter is implementation-defined.]}
1718 @ChgImplDef{Version=[2],Kind=[Added],Text=[@Chg{Version=[2],New=[Existence and
1719 meaning of second parameter of @nt{pragma} Unsuppress.],Old=[]}]}
1720 @end{ImplPerm}
1721
1722 @begin{ImplAdvice}
1723 The implementation should minimize the code executed for checks
1724 that have been suppressed.
1725 @ChgImplAdvice{Version=[2],Kind=[Added],Text=[@ChgAdded{Version=[2],
1726 Text=[Code executed for checks
1727 that have been suppressed should be minimized.]}]}
1728 @begin{ImplNote}
1729 However, if a given check comes for free (for example, the hardware
1730 automatically performs the check in parallel with doing useful work)
1731 or nearly free (for example, the check is a tiny portion of an
1732 expensive run-time system call), the implementation should not bother to
1733 suppress the check. Similarly, if the implementation detects the failure at
1734 compile time and provides a warning message, there is no need to actually
1735 suppress the check.
1736 @end{ImplNote}
1737 @end{ImplAdvice}
1738
1739 @begin{Notes}
1740 @Defn{optimization}
1741 @Defn{efficiency}
1742 There is no guarantee that a suppressed check is actually removed;
1743 hence a @nt{pragma} Suppress should be used only for efficiency reasons.
1744
1745 @ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00224-01]}
1746 @ChgAdded{Version=[2],Text=[It is possible to give both a @nt{pragma} Suppress
1747 and Unsuppress for the same check immediately within the same
1748 @nt{declarative_part}.
1749 In that case, the last @nt{pragma} given determines whether or not the check is
1750 suppressed. Similarly, it is possible to resuppress a check which has been
1751 unsuppressed by giving a @nt{pragma} Suppress in an inner declarative region.]}
1752 @end{Notes}
1753
1754 @begin{Examples}
1755 @Leading@Keepnext@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1756 @i{Examples of suppressing @Chg{Version=[2],New=[and unsuppressing ],Old=[]}checks:}
1757 @begin{Example}
1758 @ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00224-01]}
1759 @key[pragma] Suppress(@Chg{Version=[2],New=[Index_Check);
1760 @key[pragma] Unsuppress(Overflow_Check);],Old=[Range_Check);
1761 @key[pragma] Suppress(Index_Check, On => Table);]}
1762 @end{Example}
1763 @end{Examples}
1764
1765 @begin{Extend83}
1766 @Defn{extensions to Ada 83}
1767 A @nt{pragma} Suppress is allowed as a configuration pragma.
1768 A @nt{pragma} Suppress without a @nt<name> is allowed in a
1769 @nt{package_specification}.
1770
1771 Additional check names are added.
1772 We allow implementations to define their own checks.
1773 @end{Extend83}
1774
1775 @begin{DiffWord83}
1776 We define the checks in a distributed manner.
1777 Therefore, the long list of what checks apply to what
1778 is merely a NOTE.
1779
1780 We have removed the detailed rules about what is allowed
1781 in a @nt{pragma} Suppress,
1782 and allow implementations to invent their own.
1783 The RM83 rules weren't quite right,
1784 and such a change is necessary anyway in the presence
1785 of implementation-defined checks.
1786
1787 We make it clear that the difference between a Range_Check
1788 and an Overflow_Check is fuzzy.
1789 This was true in Ada 83,
1790 given RM83-11.6,
1791 but it was not clear.
1792 We considered removing Overflow_Check from the language
1793 or making it obsolescent, just as we did for Numeric_Error.
1794 However, we kept it for upward compatibility,
1795 and because it may be useful on machines where range checking
1796 costs more than overflow checking,
1797 but overflow checking still costs something.
1798 Different compilers will suppress different checks when asked to
1799 suppress Overflow_Check @em
1800 the non-uniformity in this case is not harmful,
1801 and removing it would have a serious impact on optimizers.
1802
1803 Under Access_Check,
1804 dereferences cover the cases of
1805 @nt{selected_component}, @nt{indexed_component}, @nt{slice},
1806 and attribute that are listed in RM83,
1807 as well as the new @nt{explicit_dereference},
1808 which was included in @nt{selected_component} in RM83.
1809 @end{DiffWord83}
1810
1811 @begin{Extend95}
1812 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00224-01]}
1813 @ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95}Pragma Unsuppress is new.]}
1814
1815 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00280-01]}
1816 @ChgAdded{Version=[2],Text=[Allocation_Check was added to support suppressing
1817 the new check on @nt{allocator}s (see @RefSecNum{Allocators}).]}
1818 @end{Extend95}
1819
1820 @begin{DiffWord95}
1821 @ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0036],ARef=[AI95-00176-01],ARef=[AI95-00224-01]}
1822 @ChgAdded{Version=[2],Text=[The description of Access_Check was corrected by the
1823 Corrigendum to include the discriminant case. This change was then replaced
1824 by the more general notion of checking conversions to subtypes that exclude
1825 null in Ada 2005.]}
1826
1827 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00224-01]}
1828 @ChgAdded{Version=[2],Text=[The On parameter of pragma Suppress was moved to
1829 Annex J.
1830 This feature's effect is inherently non-portable, depending on the
1831 implementation's model of computation. Compiler surveys demonstrated this,
1832 showing that implementations vary widely in the interpretation of these
1833 parameters, even on the same target. While this is relatively harmless for
1834 Suppress (which is never required to do anything), it would be a significant
1835 problem for Unsuppress (we want the checks to be made for all implementations).
1836 By moving it, we avoid needing to define the meaning of Unsuppress with an
1837 On parameter.]}
1838
1839 @ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00280-01]}
1840 @ChgAdded{Version=[2],Text=[The order of the
1841 Program_Error checks was corrected to be alphabetical.]}
1842 @end{DiffWord95}
1843
1844 @LabeledClause{Exceptions and Optimization}
1845
1846 @begin{Intro}
1847 @redundant[@Defn{language-defined check}
1848 @Defn2{Term=[check], Sec=(language-defined)}
1849 @Defn{run-time error}
1850 @Defn2{Term=[error], Sec=(run-time)}
1851 @Defn{optimization}
1852 @Defn{efficiency}
1853 This clause gives permission to the implementation to perform
1854 certain @lquotes@;optimizations@rquotes@; that do not necessarily preserve the canonical
1855 semantics.]
1856 @end{Intro}
1857
1858 @begin{RunTime}
1859 @Defn{canonical semantics}
1860 The rest of this International Standard (outside this clause)
1861 defines the @i{canonical semantics} of the language.
1862 @Redundant[The canonical semantics of a given (legal) program determines a
1863 set of possible external effects that can result from the execution of
1864 the program with given inputs.]
1865 @begin{Ramification}
1866 Note that the canonical semantics is a set of possible behaviors,
1867 since some reordering, parallelism, and non-determinism is allowed by
1868 the canonical semantics.
1869 @end{Ramification}
1870 @begin{Discussion}
1871 @Leading@;The following parts of the canonical semantics are of particular
1872 interest to the reader of this clause:
1873 @begin{Itemize}
1874 Behavior in the presence of abnormal objects
1875 and objects with invalid representations
1876 (see @RefSecNum{Data Validity}).
1877
1878 Various actions that are defined to occur in an arbitrary order.
1879
1880 Behavior in the presence of a misuse of Unchecked_Deallocation,
1881 Unchecked_Access, or imported or exported entity
1882 (see Section 13).
1883 @end{Itemize}
1884 @end{Discussion}
1885
1886 @Redundant[As explained in
1887 @RefSec{Conformity of an Implementation with the Standard},
1888 the external effect of a program is defined in terms of its
1889 interactions with its external environment.
1890 Hence, the implementation can perform any internal
1891 actions whatsoever, in any order or in parallel,
1892 so long as the external effect of the execution of the program is one
1893 that is allowed by the canonical semantics, or by the rules
1894 of this clause.]
1895 @begin{Ramification}
1896 Note that an optimization can change the external effect of the program,
1897 so long as the changed external effect is an external effect that is
1898 allowed by the semantics.
1899 Note that the canonical semantics of an erroneous execution allows any
1900 external effect whatsoever.
1901 Hence, if the implementation can prove that program execution will be
1902 erroneous in certain circumstances,
1903 there need not be any constraints on the machine code executed in those
1904 circumstances.
1905 @end{Ramification}
1906 @end{RunTime}
1907
1908 @begin{ImplPerm}
1909 @Leading@;The following additional permissions are granted to the
1910 implementation:
1911 @begin{Itemize}
1912 @Defn{extra permission to avoid raising exceptions}
1913 @Defn{undefined result}
1914 An implementation need not always
1915 raise an exception when a language-defined check fails.
1916 Instead, the operation that failed the check can simply yield
1917 an @i{undefined result}. The exception need be raised
1918 by the implementation only if, in the absence of raising it,
1919 the value of this undefined result would have some effect on
1920 the external interactions of the program.
1921 In determining this, the implementation shall not presume that
1922 an undefined result has a value that belongs to its subtype,
1923 nor even to the base range of its type, if scalar.
1924 @Redundant[Having removed the raise of the exception, the
1925 canonical semantics will in general allow the implementation
1926 to omit the code for the check, and some or all of the operation itself.]
1927 @begin{Ramification}
1928 Even without this permission, an implementation can always
1929 remove a check if it cannot possibly fail.
1930 @end{Ramification}
1931 @begin{Reason}
1932 We express the permission in terms of removing
1933 the raise, rather than the operation or the check,
1934 as it minimizes the disturbance to the canonical
1935 semantics (thereby simplifying reasoning). By allowing
1936 the implementation to omit the raise, it thereby does
1937 not need to "look" at what happens in the exception handler
1938 to decide whether the optimization is allowed.
1939 @end{Reason}
1940 @begin{Discussion}
1941 The implementation can also omit checks
1942 if they cannot possibly fail,
1943 or if they could only fail in erroneous executions.
1944 This follows from the canonical semantics.
1945 @end{Discussion}
1946 @begin{ImplNote}
1947 @Leading@;This permission is intended to allow normal "dead code removal"
1948 optimizations, even if some of the removed code might have failed
1949 some language-defined check.
1950 However, one may not eliminate the raise of an exception
1951 if subsequent code presumes in some way that the check succeeded.
1952 For example:
1953 @begin{Example}
1954 @key[if] X * Y > Integer'Last @key[then]
1955 Put_Line("X * Y overflowed");
1956 @key[end] @key[if];
1957 @key[exception]
1958 @key[when] @key[others] =>
1959 Put_Line("X * Y overflowed");
1960 @end{Example}
1961 @ChgNote{The following paragraph is missing a number in the original version.
1962 To give it a number in the new version, it is marked as an insertion.}
1963 @ChgRef{Version=[0],Kind=[Added]}
1964 @Chg{New=[],Old=[@Noparanum@;]}If X*Y does overflow, you may not remove the raise of the exception
1965 if the code that does the comparison against Integer'Last presumes
1966 that it is comparing it with an in-range Integer value, and hence
1967 always yields False.
1968
1969 @Leading@;As another example where a raise may not be eliminated:
1970 @begin{Example}
1971 @key[subtype] Str10 @key[is] String(1..10);
1972 @key[type] P10 @key[is] @key[access] Str10;
1973 X : P10 := @key[null];
1974 @key[begin]
1975 @key[if] X.all'Last = 10 @key[then]
1976 Put_Line("Oops");
1977 @key[end] @key[if];
1978 @end{Example}
1979 @ChgNote{The following paragraph is missing a number in the original version.
1980 To give it a number in the new version, it is marked as an insertion.}
1981 @ChgRef{Version=[0],Kind=[Added]}
1982 In the above code, it would be wrong to eliminate the
1983 raise of Constraint_Error on the "X.all" (since X is null),
1984 if the code to evaluate 'Last always yields 10 by presuming
1985 that X.all belongs to the subtype Str10, without even "looking."
1986 @end{ImplNote}
1987
1988 @Defn{extra permission to reorder actions}
1989 If an exception is raised due to the failure
1990 of a language-defined check,
1991 then upon
1992 reaching the corresponding @nt<exception_handler> (or the
1993 termination of the task, if none), the external interactions
1994 that have occurred need reflect only that the exception was
1995 raised somewhere within
1996 the execution of the @nt<sequence_of_statements> with the handler
1997 (or the @nt<task_body>), possibly earlier (or later
1998 if the interactions are independent of the result of the checked
1999 operation)
2000 than that defined
2001 by the canonical semantics, but not within the execution of some
2002 abort-deferred operation or @i(independent) subprogram
2003 that does not dynamically enclose the execution of the construct
2004 whose check failed.
2005 @Defn{independent subprogram}
2006 An independent subprogram is one that is
2007 defined outside the library unit containing the construct whose check
2008 failed, and has no Inline @nt<pragma> applied to it.
2009 @Defn{normal state of an object}
2010 @PDefn{abnormal state of an object}
2011 @PDefn{disruption of an assignment}
2012 Any assignment that occurred outside of such abort-deferred
2013 operations or independent subprograms can be disrupted
2014 by the raising of the exception,
2015 causing the object or its parts to become abnormal,
2016 and certain subsequent uses of the object to be erroneous,
2017 as explained in @RefSecNum{Data Validity}.
2018 @begin{Reason}
2019 We allow such variables to become abnormal so that
2020 assignments (other than to atomic variables) can be disrupted
2021 due to @lquotes@;imprecise@rquotes@; exceptions or instruction scheduling,
2022 and so that assignments can be reordered
2023 so long as the correct results are produced in the end if
2024 no language-defined checks fail.
2025 @end{Reason}
2026 @begin{Ramification}
2027 If a check fails, no result dependent on the check may be
2028 incorporated in an external interaction. In other words,
2029 there is no permission to output meaningless results due
2030 to postponing a check.
2031 @end{Ramification}
2032 @end{Itemize}
2033 @begin{Discussion}
2034 We believe it is important to state the
2035 extra permission to reorder actions
2036 in terms of what the programmer can expect at run time,
2037 rather than in terms of what the implementation can assume,
2038 or what transformations the implementation can perform.
2039 Otherwise, how can the programmer write reliable programs?
2040
2041 This clause has two conflicting goals:
2042 to allow as much optimization as possible,
2043 and to make program execution as predictable as possible
2044 (to ease the writing of reliable programs).
2045 The rules given above represent a compromise.
2046
2047 Consider the two extremes:
2048
2049 The extreme conservative rule would be
2050 to delete this clause entirely.
2051 The semantics of Ada would be the canonical semantics.
2052 This achieves the best predictability.
2053 It sounds like a disaster from the efficiency point of view,
2054 but in practice, implementations would provide modes
2055 in which less predictability but more efficiency would be achieved.
2056 Such a mode could even be the out-of-the-box mode.
2057 In practice, implementers would provide a compromise based on their
2058 customer's needs.
2059 Therefore, we view this as one viable alternative.
2060
2061 The extreme liberal rule would be @lquotes@;the language does not specify the
2062 execution of a program once a language-defined check has failed;
2063 such execution can be unpredictable.@rquotes@;
2064 This achieves the best efficiency.
2065 It sounds like a disaster from the predictability point of view,
2066 but in practice it might not be so bad.
2067 A user would have to assume that exception handlers for exceptions
2068 raised by language-defined checks are not portable.
2069 They would have to isolate such code (like all nonportable code),
2070 and would have to find out, for each implementation of interest,
2071 what behaviors can be expected.
2072 In practice, implementations would tend to avoid going so far as to
2073 punish their customers too much in terms of predictability.
2074
2075 The most important thing about this clause
2076 is that users understand what they can expect at run time,
2077 and implementers understand what optimizations are allowed.
2078 Any solution that makes this clause contain rules that can
2079 interpreted in more than one way is unacceptable.
2080
2081 We have chosen a compromise between the extreme conservative and
2082 extreme liberal rules.
2083 The current rule essentially allows arbitrary optimizations within
2084 a library unit and inlined subprograms reachable from it, but
2085 disallow semantics-disrupting optimizations across library units
2086 in the absence of inlined subprograms.
2087 This allows a library unit to be debugged, and then reused with
2088 some confidence that the abstraction it manages cannot be
2089 broken by bugs outside the library unit.
2090 @end{Discussion}
2091 @end{ImplPerm}
2092
2093 @begin{Notes}
2094 The permissions granted by this clause can have an effect on the
2095 semantics of a program only if the program fails a language-defined check.
2096 @end{Notes}
2097
2098 @begin{DiffWord83}
2099 @Leading@;RM83-11.6 was unclear.
2100 It has been completely rewritten here; we hope this version is clearer.
2101 Here's what happened to each paragraph of RM83-11.6:
2102 @begin{Itemize}
2103 Paragraphs 1 and 2 contain no semantics;
2104 they are merely pointing out that anything goes if the canonical
2105 semantics is preserved.
2106 We have similar introductory paragraphs,
2107 but we have tried to clarify that these are not granting any @lquotes@;extra@rquotes@;
2108 permission beyond what the rest of the document allows.
2109
2110 Paragraphs 3 and 4 are reflected in the
2111 @lquotes@;extra permission to reorder actions@rquotes@;.
2112 Note that this permission now allows the reordering of assignments in
2113 many cases.
2114
2115 Paragraph 5 is moved to @RefSec{Operators and Expression Evaluation},
2116 where operator association is discussed.
2117 Hence, this is no longer an @lquotes@;extra permission@rquotes@;
2118 but is part of the canonical semantics.
2119
2120 Paragraph 6 now follows from the general permission to store
2121 out-of-range values for unconstrained subtypes.
2122 Note that the parameters and results of all the predefined operators
2123 of a type are of the unconstrained subtype of the type.
2124
2125 Paragraph 7 is reflected in the
2126 @lquotes@;extra permission to avoid raising exceptions@rquotes@;.
2127 @end{Itemize}
2128
2129 We moved clause @RefSec{Suppressing Checks} from after 11.6 to
2130 before 11.6, in order to preserve the famous number @lquotes@;11.6@rquotes@;
2131 (given the changes to earlier clauses in Section 11).
2132 @end{DiffWord83}