| 1 |
@Part(06, Root="ada.mss") |
| 2 |
|
| 3 |
@Comment{$Date: 2016/02/09 04:55:40 $} |
| 4 |
@LabeledSection{Subprograms} |
| 5 |
|
| 6 |
@Comment{$Source: e:\\cvsroot/ARM/Source/06.mss,v $} |
| 7 |
@Comment{$Revision: 1.137 $} |
| 8 |
|
| 9 |
@begin{Intro} |
| 10 |
@Defn{subprogram} |
| 11 |
@Defn{procedure} |
| 12 |
@Defn{function} |
| 13 |
A subprogram is a program unit or intrinsic operation whose execution |
| 14 |
is invoked by a subprogram call. |
| 15 |
There are two forms of subprogram: procedures and functions. |
| 16 |
A procedure call is a @nt{statement}; a function call is an expression and |
| 17 |
returns a value. |
| 18 |
The definition of a subprogram can be given in two parts: |
| 19 |
a subprogram declaration defining its interface, |
| 20 |
and a @nt{subprogram_body} defining its execution. |
| 21 |
@Redundant[Operators and enumeration literals are functions.] |
| 22 |
@begin{Honest} |
| 23 |
A function call is an expression, but more specifically it is a @nt<name>. |
| 24 |
@end{Honest} |
| 25 |
@ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Subprogram>, |
| 26 |
Text=<@ChgAdded{Version=[2],Text=[A subprogram is a section of a program that |
| 27 |
can be executed in various contexts. It is invoked by a subprogram call that |
| 28 |
may qualify the effect of the subprogram through the passing of parameters. |
| 29 |
There are two forms of subprograms: functions, which return values, and |
| 30 |
procedures, which do not.]}>} |
| 31 |
@ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Function>, |
| 32 |
Text=<@ChgAdded{Version=[2],Text=[A function is a form of subprogram that |
| 33 |
returns a result and can be called as part of an expression.]}>} |
| 34 |
@ChgToGlossary{Version=[2],Kind=[AddedNormal],Term=<Procedure>, |
| 35 |
Text=<@ChgAdded{Version=[2],Text=[A procedure is a form of subprogram that |
| 36 |
does not return a result and can only be called by a @nt{statement}.]}>} |
| 37 |
|
| 38 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 39 |
@Defn{callable entity} |
| 40 |
A @i(callable entity) is a subprogram or entry (see |
| 41 |
@Chg{Version=[3],New=[Section 9],Old=[@RefSecNum{Entries and Accept Statements}]}). |
| 42 |
@Defn{call} |
| 43 |
A callable entity is invoked by a @i{call}; |
| 44 |
that is, a subprogram call or entry call. |
| 45 |
@Defn{callable construct} |
| 46 |
A @i(callable construct) is a construct |
| 47 |
that defines the action of a call upon a callable entity: |
| 48 |
a @nt{subprogram_body}, |
| 49 |
@nt{entry_body}, or @nt{accept_statement}. |
| 50 |
@begin{Ramification} |
| 51 |
Note that @lquotes@;callable entity@rquotes@; |
| 52 |
includes predefined operators, enumeration literals, |
| 53 |
and abstract subprograms. |
| 54 |
@lquotes@;Call@rquotes@; includes calls of these things. |
| 55 |
They do not have callable constructs, |
| 56 |
since they don't have completions. |
| 57 |
@end{Ramification} |
| 58 |
@end{Intro} |
| 59 |
|
| 60 |
@LabeledClause{Subprogram Declarations} |
| 61 |
|
| 62 |
@begin{Intro} |
| 63 |
@Redundant[A @nt{subprogram_declaration} declares a procedure or |
| 64 |
function.] |
| 65 |
@end{Intro} |
| 66 |
|
| 67 |
@begin{Syntax} |
| 68 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 69 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]} |
| 70 |
@Syn{lhs=<subprogram_declaration>,rhs="@Chg{Version=[2],New=< |
| 71 |
[@Syn2{overriding_indicator}] |
| 72 |
>,Old=<>}@Syn2{subprogram_specification}@Chg{Version=[3],New=< |
| 73 |
[@Syn2{aspect_specification}]>,Old=[]};"} |
| 74 |
|
| 75 |
@ChgRef{Version=[2],Kind=[Deleted],ARef=[AI95-00348-01]} |
| 76 |
@DeletedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<>,Old=<abstract_subprogram_declaration>}>, |
| 77 |
rhs="@Chg{Version=[2],New=<>,Old=<@Syn2{subprogram_specification} @key{is} @key{abstract};>}"} |
| 78 |
|
| 79 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 80 |
@Syn{lhs=<subprogram_specification>,rhs="@Chg{Version=[2],New=[ |
| 81 |
@Syn2{procedure_specification} |
| 82 |
| @Syn2{function_specification}],Old=[ |
| 83 |
@key{procedure} @Syn2{defining_program_unit_name} @Syn2{parameter_profile} |
| 84 |
| @key{function} @Syn2{defining_designator} @Syn2{parameter_and_result_profile}]}"} |
| 85 |
|
| 86 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]} |
| 87 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<procedure_specification>,Old=<>}>, |
| 88 |
rhs="@Chg{Version=[2],New=<@key{procedure} @Syn2{defining_program_unit_name} @Syn2{parameter_profile}>,Old=<>}"} |
| 89 |
|
| 90 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00348-01]} |
| 91 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<function_specification>,Old=<>}>, |
| 92 |
rhs="@Chg{Version=[2],New=<@key{function} @Syn2{defining_designator} @Syn2{parameter_and_result_profile}>,Old=<>}"} |
| 93 |
|
| 94 |
@Syn{lhs=<designator>,rhs="[@Syn2{parent_unit_name} . ]@Syn2{identifier} | @Syn2{operator_symbol}"} |
| 95 |
|
| 96 |
@Syn{lhs=<defining_designator>, |
| 97 |
rhs="@Syn2{defining_program_unit_name} | @Syn2{defining_operator_symbol}"} |
| 98 |
|
| 99 |
@Syn{lhs=<defining_program_unit_name>,rhs="[@Syn2{parent_unit_name} . ]@Syn2{defining_identifier}"} |
| 100 |
|
| 101 |
@begin{SyntaxText} |
| 102 |
@Redundant[The optional @nt{parent_unit_name} is only allowed for |
| 103 |
library units (see @RefSecNum{Compilation Units - Library Units}).] |
| 104 |
@end{SyntaxText} |
| 105 |
|
| 106 |
@Syn{lhs=<operator_symbol>,rhs="@Syn2{string_literal}"} |
| 107 |
|
| 108 |
@begin{SyntaxText} |
| 109 |
|
| 110 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00395-01]} |
| 111 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 112 |
The sequence of characters in an @nt{operator_symbol} shall @Chg{Version=[2], |
| 113 |
New=[form a reserved |
| 114 |
word, a delimiter, or compound delimiter that corresponds],Old=[correspond]} to |
| 115 |
an operator belonging to one of the six @Chg{Version=[2],New=[categories], |
| 116 |
Old=[classes]} of operators |
| 117 |
defined in @Chg{Version=[3],New=[subclause],Old=[clause]} @RefSecNum{Operators and Expression Evaluation}@Chg{Version=[2], |
| 118 |
New=[],Old=[(spaces are not allowed and the case of letters |
| 119 |
is not significant)]}. |
| 120 |
|
| 121 |
@begin{Reason} |
| 122 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]} |
| 123 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0090-1]} |
| 124 |
@ChgAdded{Version=[2],Text=[The @ldquote@;sequence of characters@rdquote |
| 125 |
of the string literal of the operator is a technical term (see |
| 126 |
@RefSecNum{String Literals}), and does not include the surrounding quote |
| 127 |
characters. As defined in @RefSecNum{Lexical Elements, Separators, and Delimiters}, |
| 128 |
lexical elements are @lquotes@;formed@rquotes from a sequence of characters. |
| 129 |
Spaces are not allowed, and upper and lower case is |
| 130 |
not significant.@Chg{Version=[3],New=[],Old=[ See |
| 131 |
@RefSecNum{Lexical Elements, Separators, and Delimiters} and |
| 132 |
@RefSecNum{Reserved Words} for rules related to the use of @ntf{other_format} |
| 133 |
characters in delimiters and reserved words.]}]} |
| 134 |
@end{Reason} |
| 135 |
|
| 136 |
@end{SyntaxText} |
| 137 |
|
| 138 |
@Syn{lhs=<defining_operator_symbol>,rhs="@Syn2{operator_symbol}"} |
| 139 |
|
| 140 |
@Syn{lhs=<parameter_profile>,rhs="[@Syn2{formal_part}]"} |
| 141 |
|
| 142 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 143 |
@Syn{lhs=<parameter_and_result_profile>,rhs="@Chg{Version=[2],New=[ |
| 144 |
],Old=[]}[@Syn2{formal_part}] @key{return}@Chg{Version=[2],New=< [@Syn2{null_exclusion}]>,Old=<>} @Syn2{subtype_mark}@Chg{Version=[2],New=< |
| 145 |
| [@Syn2{formal_part}] @key{return} @Syn2{access_definition}>,Old=<>}"} |
| 146 |
|
| 147 |
@Syn{lhs=<formal_part>,rhs=" |
| 148 |
(@Syn2{parameter_specification} {; @Syn2{parameter_specification}})"} |
| 149 |
|
| 150 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 151 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4]} |
| 152 |
@Syn{lhs=<parameter_specification>,rhs=" |
| 153 |
@Syn2{defining_identifier_list} : @Chg{Version=[3],New=<[@key[aliased]] >,Old=<>}@Syn2{mode} @Chg{Version=[2],New=<[@Syn2{null_exclusion}]>,Old=<>} @Syn2{subtype_mark} [:= @Syn2{default_expression}] |
| 154 |
| @Syn2{defining_identifier_list} : @Syn2{access_definition} [:= @Syn2{default_expression}]"} |
| 155 |
|
| 156 |
@Syn{lhs=<mode>,rhs="[@key{in}] | @key{in} @key{out} | @key{out}"} |
| 157 |
@end{Syntax} |
| 158 |
|
| 159 |
@begin{Resolution} |
| 160 |
@Defn2{Term=[formal parameter], Sec=(of a subprogram)} |
| 161 |
A @i(formal parameter) is an object |
| 162 |
@Redundant[directly visible within a @nt{subprogram_body}] |
| 163 |
that represents the actual parameter passed to the subprogram in a |
| 164 |
call; |
| 165 |
it is declared by a @nt{parameter_specification}. |
| 166 |
@PDefn2{Term=[expected type], |
| 167 |
Sec=(parameter @nt{default_expression})} |
| 168 |
For a formal parameter, |
| 169 |
the expected type for its @nt<default_expression>, |
| 170 |
if any, is that of the formal parameter. |
| 171 |
@IndexSee{Term=[parameter],See=[formal parameter]} |
| 172 |
@end{Resolution} |
| 173 |
|
| 174 |
@begin{Legality} |
| 175 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0143-1]} |
| 176 |
@Defn{parameter mode} |
| 177 |
The @i(parameter mode) of a formal parameter conveys the direction of |
| 178 |
information transfer with the actual parameter: |
| 179 |
@key(in), @key(in out), or @key(out). |
| 180 |
Mode @key(in) is the default, |
| 181 |
and is the mode of a parameter defined by an |
| 182 |
@nt{access_definition}.@Chg{Version=[3],New=[],Old=[ The formal parameters |
| 183 |
of a function, if any, shall have the mode @key(in).]} |
| 184 |
@begin{Ramification} |
| 185 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0143-1]} |
| 186 |
@ChgDeleted{Version=[3],Text=[Access parameters are permitted. |
| 187 |
This restriction to @b(in) parameters is primarily a methodological |
| 188 |
restriction, though it also simplifies implementation for some compiler |
| 189 |
technologies.]} |
| 190 |
@end{Ramification} |
| 191 |
|
| 192 |
A @nt{default_expression} is only allowed in a @nt{parameter_specification} |
| 193 |
for a formal parameter of mode @key(in). |
| 194 |
|
| 195 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 196 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1],ARef=[AI05-0229-1]} |
| 197 |
@PDefn2{Term=[requires a completion], Sec=(@nt{subprogram_declaration})} |
| 198 |
@PDefn2{Term=[requires a completion], Sec=(@nt{generic_subprogram_declaration})} |
| 199 |
A @nt{subprogram_declaration} |
| 200 |
or a @nt{generic_subprogram_declaration} |
| 201 |
requires a completion@Chg{Version=[3],New=[],Old=[:]} |
| 202 |
@Redundant[@Chg{Version=[3],New=[unless the Import aspect (see |
| 203 |
@RefSecNum{Interfacing Aspects}) is True for the declaration; the |
| 204 |
completion shall be ],Old=[]}a body@Chg{Version=[3],New=[ or],Old=[,]} |
| 205 |
a @nt<renaming_declaration> |
| 206 |
(see @RefSecNum(Renaming Declarations))@Chg{Version=[3],New=[],Old=[, or |
| 207 |
a @Chg{Version=[2],New=[@nt{pragma}], |
| 208 |
Old=[@key(pragma)]} Import (see @RefSecNum{Interfacing Aspects})]}]. |
| 209 |
@Redundant[A completion is not allowed |
| 210 |
for an @nt<abstract_subprogram_declaration>@Chg{Version=[2],New=[ (see |
| 211 |
@RefSecNum{Abstract Types and Subprograms})@Chg{Version=[3],New=[,],Old=[ or]} a |
| 212 |
@nt{null_procedure_declaration} (see @RefSecNum{Null Procedures})@Chg{Version=[3],New=[, |
| 213 |
or an @nt{expression_function_declaration} (see @RefSecNum{Expression Functions})],Old=[]}],Old=[]}.] |
| 214 |
@begin(Ramification) |
| 215 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 216 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]} |
| 217 |
Abstract subprograms @Chg{Version=[2],New=[@Chg{Version=[3],New=[,],Old=[and]} |
| 218 |
null procedures@Chg{Version=[3],New=[, and expression functions],Old=[]} ],Old=[]}are |
| 219 |
not declared by @nt{subprogram_declaration}s, and so do not require |
| 220 |
completion@Chg{Version=[3],New=[ (although the latter two can @i<be> completions)],Old=[]}. |
| 221 |
Protected subprograms are declared by @nt{subprogram_declaration}s, |
| 222 |
and so require completion. |
| 223 |
Note that an abstract subprogram is a subprogram, |
| 224 |
@Chg{Version=[3],New=[a null procedure is a subprogram, an expression function |
| 225 |
is a subprogram, ],Old=[]}and a protected subprogram is a subprogram, |
| 226 |
but a generic subprogram is not a subprogram.@Comment{Who's the idiot that |
| 227 |
came up with that??} |
| 228 |
@end(Ramification) |
| 229 |
@begin(TheProof) |
| 230 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 231 |
@ChgAdded{Version=[3],Text=[When the Import aspect is True for any entity, |
| 232 |
no completion is allowed (see @RefSecNum{Interfacing Aspects}).]} |
| 233 |
@end{TheProof} |
| 234 |
|
| 235 |
|
| 236 |
A @nt{name} that denotes a formal parameter |
| 237 |
is not allowed within the @nt{formal_part} in which it is declared, |
| 238 |
nor within the @nt{formal_part} of a corresponding body or |
| 239 |
@nt{accept_statement}. |
| 240 |
@begin{Ramification} |
| 241 |
By contrast, |
| 242 |
@nt<generic_formal_parameter_declaration>s are visible to subsequent |
| 243 |
declarations in the same @nt<generic_formal_part>. |
| 244 |
@end{Ramification} |
| 245 |
@end{Legality} |
| 246 |
|
| 247 |
@begin{StaticSem} |
| 248 |
@Defn{profile} |
| 249 |
The @i(profile) of (a view of) a callable entity |
| 250 |
is either a @nt{parameter_profile} or |
| 251 |
@nt{parameter_and_result_profile}@Redundant[; |
| 252 |
it embodies information about |
| 253 |
the interface to that entity @em for example, the profile includes |
| 254 |
information about parameters passed to the callable entity. |
| 255 |
All callable entities have a profile @em enumeration literals, |
| 256 |
other subprograms, and entries. |
| 257 |
An access-to-subprogram type has a designated profile.] |
| 258 |
Associated with a profile is a calling convention. |
| 259 |
A @nt<subprogram_declaration> declares a procedure or a function, as |
| 260 |
indicated by the initial reserved word, with name and profile as given by |
| 261 |
its specification. |
| 262 |
|
| 263 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 264 |
@PDefn2{Term=[nominal subtype], Sec=(of a formal parameter)} |
| 265 |
The nominal subtype of a formal parameter is |
| 266 |
the subtype @Chg{Version=[2],New=[determined],Old=[denoted]} by |
| 267 |
@Chg{Version=[2],New=[the optional @nt{null_exclusion} and ], Old=[]}the |
| 268 |
@nt{subtype_mark}, or defined by the @nt{access_definition}, in the |
| 269 |
@nt{parameter_specification}.@Chg{Version=[2],New=[ The nominal |
| 270 |
subtype of a function result is the subtype |
| 271 |
determined by the optional @nt{null_exclusion} and the @nt{subtype_mark}, or |
| 272 |
defined by the @nt{access_definition}, in the |
| 273 |
@nt{parameter_and_result_profile}. |
| 274 |
@PDefn2{Term=[nominal subtype], Sec=(of a function result)}], Old=[]} |
| 275 |
|
| 276 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4]} |
| 277 |
@ChgAdded{Version=[3],Text=[@Defn{explicitly aliased parameter}@Defn2{Term=[parameter],Sec=(explicitly aliased)}An |
| 278 |
@i(explicitly aliased parameter) is a formal parameter whose |
| 279 |
@nt{parameter_specification} includes the reserved word @key[aliased].]} |
| 280 |
|
| 281 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00254-01],ARef=[AI95-00318-02]} |
| 282 |
@Defn{access parameter} |
| 283 |
An @i(access parameter) is a formal @key[in] parameter |
| 284 |
specified by an @nt{access_definition}. |
| 285 |
@Defn{access result type} |
| 286 |
@Chg{Version=[2],New=[An @i(access result type) is a function result type specified by |
| 287 |
an @nt{access_definition}.],Old=[]} |
| 288 |
An access parameter @Chg{Version=[2],New=[or result type ],Old=[]}is of an |
| 289 |
anonymous |
| 290 |
@Chg{Version=[2],New=[access],Old=[general access-to-variable]} type (see |
| 291 |
@RefSecNum{Access Types}). @Redundant[Access parameters |
| 292 |
@Chg{Version=[2],New=[of an access-to-object type],Old=[]} allow dispatching |
| 293 |
calls to be controlled by access values.@Chg{Version=[2],New=[ Access |
| 294 |
parameters of an access-to-subprogram type permit calls to subprograms passed |
| 295 |
as parameters irrespective of their accessibility level.],Old=[]}] |
| 296 |
|
| 297 |
@begin{Discussion} |
| 298 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 299 |
@ChgAdded{Version=[2],Text=[Access result types have normal accessibility and |
| 300 |
thus don't have any special properties worth noting here.]} |
| 301 |
@end{Discussion} |
| 302 |
|
| 303 |
@leading@keepnext@Defn2{Term=[subtypes], Sec=(of a profile)} |
| 304 |
The @i(subtypes of a profile) are: |
| 305 |
@begin{Itemize} |
| 306 |
For any non-access parameters, the nominal subtype of the parameter. |
| 307 |
|
| 308 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00254-01]} |
| 309 |
For any access parameters@Chg{Version=[2],New=[ of an access-to-object type],Old=[]}, |
| 310 |
the designated subtype of the parameter type. |
| 311 |
|
| 312 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01]} |
| 313 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0164-1]} |
| 314 |
@ChgAdded{Version=[2],Text=[For any access parameters of an access-to-subprogram |
| 315 |
type, the subtypes of the @Chg{Version=[3],New=[designated ],Old=[]}profile |
| 316 |
of the parameter type.]} |
| 317 |
|
| 318 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01],ARef=[AI95-00318-02]} |
| 319 |
@Chg{Version=[2],New=[For any non-access result, the nominal subtype of the |
| 320 |
function result.],Old=[For any result, the result subtype.]} |
| 321 |
|
| 322 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 323 |
@Chg{Version=[2],New=[For any access result type of an access-to-object type, |
| 324 |
the designated subtype of the result type.],Old=[]} |
| 325 |
|
| 326 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 327 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0164-1]} |
| 328 |
@Chg{Version=[2],New=[For any access result type of an access-to-subprogram |
| 329 |
type, the subtypes of the @Chg{Version=[3],New=[designated ],Old=[]}profile |
| 330 |
of the result type.],Old=[]} |
| 331 |
|
| 332 |
@end{Itemize} |
| 333 |
|
| 334 |
@Redundant[@Defn2{Term=[types], Sec=(of a profile)} |
| 335 |
The @i{types of a profile} are the types of those subtypes.] |
| 336 |
|
| 337 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 338 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]} |
| 339 |
@Redundant[A subprogram declared by an |
| 340 |
@nt<abstract_subprogram_declaration> |
| 341 |
is abstract; a subprogram declared by a @nt<subprogram_declaration> |
| 342 |
is not. See @RefSec{Abstract Types and Subprograms}.@Chg{Version=[2],New=[ |
| 343 |
Similarly, a procedure @Chg{Version=[3],New=[declared],Old=[defined]} by a |
| 344 |
@nt{null_procedure_declaration} is a null procedure; a procedure declared by |
| 345 |
a @nt{subprogram_declaration} is not. See @RefSec{Null Procedures}.@Chg{Version=[3],New=[ |
| 346 |
Finally, a function declared by an @nt{expression_function_declaration} is |
| 347 |
an expression function; a function declared by |
| 348 |
a @nt{subprogram_declaration} is not. See @RefSec{Expression Functions}.],Old=[]}],Old=[]}] |
| 349 |
|
| 350 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00218-03]} |
| 351 |
@ChgAdded{Version=[2],Text=[@Redundant[An @nt{overriding_indicator} is used to |
| 352 |
indicate whether overriding is intended. See @RefSec{Overriding Indicators}.]]} |
| 353 |
@end{StaticSem} |
| 354 |
|
| 355 |
@begin{RunTime} |
| 356 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 357 |
@PDefn2{Term=[elaboration], Sec=(subprogram_declaration)}@Chg{Version=[2],New=[],Old=[ |
| 358 |
@PDefn2{Term=[elaboration], Sec=(abstract_subprogram_declaration)}]} |
| 359 |
The elaboration of a @nt{subprogram_declaration}@Chg{Version=[2],New=[],Old=[ |
| 360 |
or an @nt{abstract_subprogram_declaration}]} has no effect. |
| 361 |
@end{RunTime} |
| 362 |
|
| 363 |
@begin{Notes} |
| 364 |
A @nt{parameter_specification} with several identifiers is equivalent |
| 365 |
to a sequence of single @nt{parameter_specification}s, as explained |
| 366 |
in @RefSecNum{Objects and Named Numbers}. |
| 367 |
|
| 368 |
Abstract subprograms do not have bodies, and cannot be used |
| 369 |
in a nondispatching call (see @RefSec{Abstract Types and Subprograms}). |
| 370 |
|
| 371 |
The evaluation of @nt<default_expression>s is caused by certain |
| 372 |
calls, as described in @RefSecNum{Parameter Associations}. |
| 373 |
They are not evaluated during the elaboration of |
| 374 |
the subprogram declaration. |
| 375 |
|
| 376 |
Subprograms can be called recursively and can be called |
| 377 |
concurrently from multiple tasks. |
| 378 |
@end{Notes} |
| 379 |
|
| 380 |
@begin{Examples} |
| 381 |
@leading@keepnext@i{Examples of subprogram declarations:} |
| 382 |
@begin{Example} |
| 383 |
@key[procedure] Traverse_Tree; |
| 384 |
@key[procedure] Increment(X : @key[in] @key[out] Integer); |
| 385 |
@key[procedure] Right_Indent(Margin : @key[out] Line_Size); --@RI{ see @RefSecNum{Integer Types}} |
| 386 |
@key[procedure] Switch(From, To : @key[in] @key[out] Link); --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 387 |
|
| 388 |
@key[function] Random @key[return] Probability; --@RI{ see @RefSecNum{Floating Point Types}} |
| 389 |
|
| 390 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0056-1]} |
| 391 |
@key[function] Min_Cell(X : Link) @key[return] Cell; --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 392 |
@key[function] Next_Frame(K : Positive) @key[return] Frame; --@RI{ see @RefSecNum{Access Types}} |
| 393 |
@key[function] Dot_Product(Left, Right : Vector) @key[return] Real; --@RI{ see @RefSecNum{Array Types}}@Chg{Version=[4],New=[ |
| 394 |
@key[function] Find(B : @key[aliased in out] Barrel; Key : String) @key[return] Real; |
| 395 |
--@RI{ see @RefSecNum{User-Defined References}}],Old=[]} |
| 396 |
|
| 397 |
@key[function] "*"(Left, Right : Matrix) @key[return] Matrix; --@RI{ see @RefSecNum{Array Types}} |
| 398 |
@end{Example} |
| 399 |
|
| 400 |
@begin{WideAbove} |
| 401 |
@leading@keepnext@i{Examples of @key[in] parameters with default expressions:} |
| 402 |
@end{WideAbove} |
| 403 |
@begin{Example} |
| 404 |
@key[procedure] Print_Header(Pages : @key[in] Natural; |
| 405 |
Header : @key[in] Line := (1 .. Line'Last => ' '); --@RI{ see @RefSecNum{Array Types}} |
| 406 |
Center : @key[in] Boolean := True); |
| 407 |
@end{Example} |
| 408 |
@end{Examples} |
| 409 |
|
| 410 |
@begin{Extend83} |
| 411 |
@Defn{extensions to Ada 83} |
| 412 |
The syntax for @nt{abstract_subprogram_declaration} is added. |
| 413 |
The syntax for @nt{parameter_specification} is revised to allow |
| 414 |
for access parameters (see @RefSecNum{Access Types}) |
| 415 |
|
| 416 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 417 |
Program units that are library units may have |
| 418 |
a @nt{parent_unit_name} to indicate the parent of a child |
| 419 |
(see @Chg{Version=[3],New=[@RefSecNum{Compilation Units - Library Units}],Old=[Section 10]}). |
| 420 |
@end{Extend83} |
| 421 |
|
| 422 |
@begin{DiffWord83} |
| 423 |
We have incorporated the rules from |
| 424 |
RM83-6.5, @lquotes@;Function Subprograms@rquotes@; here and in |
| 425 |
@RefSec{Subprogram Bodies} |
| 426 |
|
| 427 |
We have incorporated the definitions of RM83-6.6, @lquotes@;Parameter and Result |
| 428 |
Type Profile - Overloading of Subprograms@rquotes@; here. |
| 429 |
|
| 430 |
The syntax rule for @nt{defining_operator_symbol} is new. |
| 431 |
It is used for the defining occurrence of an @nt{operator_symbol}, |
| 432 |
analogously to @nt{defining_identifier}. |
| 433 |
Usage occurrences use the @nt{direct_name} or @nt{selector_name} |
| 434 |
syntactic categories. |
| 435 |
The syntax rules for @nt{defining_designator} and |
| 436 |
@nt{defining_program_unit_name} are new. |
| 437 |
@end{DiffWord83} |
| 438 |
|
| 439 |
@begin{Extend95} |
| 440 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 441 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 442 |
Subprograms now allow @nt{overriding_indicator}s for better error checking |
| 443 |
of overriding.]} |
| 444 |
|
| 445 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]} |
| 446 |
@ChgAdded{Version=[2],Text=[An optional @nt{null_exclusion} can be used in a |
| 447 |
formal parameter declaration. Similarly, an optional @nt{null_exclusion} can |
| 448 |
be used in a function result.]} |
| 449 |
|
| 450 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 451 |
@ChgAdded{Version=[2],Text=[The return type of a function can be an |
| 452 |
anonymous access type.]} |
| 453 |
@end{Extend95} |
| 454 |
|
| 455 |
@begin{DiffWord95} |
| 456 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00254-01]} |
| 457 |
@ChgAdded{Version=[2],Text=[A description of the purpose of anonymous |
| 458 |
access-to-subprogram parameters and the definition of the profile of |
| 459 |
subprograms containing them was added.]} |
| 460 |
|
| 461 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 462 |
@ChgAdded{Version=[2],Text=[Split the production for |
| 463 |
@nt{subprogram_specification} in order to make the declaration |
| 464 |
of null procedures (see @RefSecNum{Null Procedures}) easier.]} |
| 465 |
|
| 466 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 467 |
@ChgAdded{Version=[2],Text=[Moved the @SyntaxTitle and |
| 468 |
@RuntimeTitle for @nt{abstract_subprogram_declaration} to |
| 469 |
@RefSecNum{Abstract Types and Subprograms}, so that the syntax |
| 470 |
and semantics are together. This also keeps abstract and null |
| 471 |
subprograms similar.]} |
| 472 |
|
| 473 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00395-01]} |
| 474 |
@ChgAdded{Version=[2],Text=[Revised to allow @ntf{other_format} characters |
| 475 |
in @nt{operator_symbol}s in the same way as the underlying constructs.]} |
| 476 |
@end{DiffWord95} |
| 477 |
|
| 478 |
@begin{Extend2005} |
| 479 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 480 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}Parameters can |
| 481 |
now be explicitly aliased, allowing parts of function results to |
| 482 |
designate parameters and forcing by-reference parameter passing.]} |
| 483 |
|
| 484 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0143-1]} |
| 485 |
@ChgAdded{Version=[3],Text=[The parameters |
| 486 |
of a function can now have any mode.]} |
| 487 |
|
| 488 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 489 |
@ChgAdded{Version=[3],Text=[An optional @nt{aspect_specification} can be |
| 490 |
used in a @nt{subprogram_declaration}. |
| 491 |
This is described in @RefSecNum{Aspect Specifications}.]} |
| 492 |
@end{Extend2005} |
| 493 |
|
| 494 |
@begin{DiffWord2005} |
| 495 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 496 |
@ChgAdded{Version=[3],Text=[Added expression functions (see |
| 497 |
@RefSecNum{Expression Functions}) to the wording.]} |
| 498 |
@end{DiffWord2005} |
| 499 |
|
| 500 |
|
| 501 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 502 |
@LabeledAddedSubClause{Version=[3],Name=[Preconditions and Postconditions]} |
| 503 |
|
| 504 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1]} |
| 505 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0045-1]} |
| 506 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For a |
| 507 |
@Chg{Version=[4],New=[noninstance ],Old=[]}subprogram@Chg{Version=[4],New=[, |
| 508 |
a generic subprogram,],Old=[]} or @Chg{Version=[4],New=[an ],Old=[]}entry, |
| 509 |
the following language-defined aspects may be specified with an |
| 510 |
@nt{aspect_specification} (see @RefSecNum{Aspect Specifications}):]} |
| 511 |
|
| 512 |
@begin{Ramification} |
| 513 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0045-1]} |
| 514 |
@ChgAdded{Version=[4],Text=[@ldquote@;Noninstance subprogram@rdquote excludes |
| 515 |
a subprogram that is an instance of a generic subprogram. In that case, the |
| 516 |
aspects should be specified on the generic subprogram. If preconditions or |
| 517 |
postconditions need to be added to an instance of a generic subprogram, it |
| 518 |
can be accomplished by creating a separate subprogram specification and then |
| 519 |
completing that specification with a renames-as-body of the instance.]} |
| 520 |
@end{Ramification} |
| 521 |
|
| 522 |
@begin{Description} |
| 523 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 524 |
@ChgAdded{Version=[3],Text=[Pre@\This aspect |
| 525 |
specifies a specific precondition for a callable entity; it shall |
| 526 |
be specified by an @nt{expression}, called a |
| 527 |
@i<specific precondition |
| 528 |
expression>.@Defn{specific precondition expression}@Defn2{Term=[precondition expression],Sec=[specific]} |
| 529 |
If not specified for an entity, the specific precondition |
| 530 |
expression for the entity is the enumeration literal |
| 531 |
True.@AspectDefn{Pre}]} |
| 532 |
|
| 533 |
@begin{Honest} |
| 534 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 535 |
@ChgAdded{Version=[3],Text=[In this and the following rules, we are talking |
| 536 |
about the enumeration literal True declared in package Standard (see |
| 537 |
@RefSecNum{The Package Standard}), and not some |
| 538 |
other value or identifier True. That matters as some rules depend on full |
| 539 |
conformance of these expressions, which depends on the specific declarations |
| 540 |
involved.]} |
| 541 |
@end{Honest} |
| 542 |
|
| 543 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pre], |
| 544 |
Text=[@ChgAdded{Version=[3],Text=[Precondition; a condition that must hold |
| 545 |
true before a call.]}]} |
| 546 |
|
| 547 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0254-1],ARef=[AI05-0262-1]} |
| 548 |
@ChgAdded{Version=[3],Text=[Pre'Class@\This aspect |
| 549 |
specifies a class-wide precondition for an operation of a tagged type and its |
| 550 |
descendants; it shall be specified by an @nt{expression}, called a |
| 551 |
@i<class-wide precondition expression>.@Defn{class-wide precondition expression}@Defn2{Term=[precondition expression],Sec=[class-wide]} |
| 552 |
If not specified for an entity, then if no other |
| 553 |
class-wide precondition applies to the entity, the class-wide precondition |
| 554 |
expression for the entity is the enumeration literal |
| 555 |
True.@AspectDefn{Pre'Class}]} |
| 556 |
|
| 557 |
@begin{Ramification} |
| 558 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0254-1]} |
| 559 |
@ChgAdded{Version=[3],Text=[If other class-wide preconditions apply to the |
| 560 |
entity and no class-wide precondition is specified, no class-wide precondition |
| 561 |
is defined for the entity; of course, the class-wide preconditions (of |
| 562 |
ancestors) that apply are still going to be checked. We need subprograms that |
| 563 |
don't have ancestors and don't specify a class-wide precondition to have a |
| 564 |
class-wide precondition of True, so that adding such a precondition to a |
| 565 |
descendant has no effect (necessary as a dispatching call through the root |
| 566 |
routine would not check any precondition).]} |
| 567 |
@end{Ramification} |
| 568 |
|
| 569 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Pre'Class], |
| 570 |
Text=[@ChgAdded{Version=[3],Text=[Precondition inherited on type |
| 571 |
derivation.]}]} |
| 572 |
|
| 573 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 574 |
@ChgAdded{Version=[3],Text=[Post@\This aspect |
| 575 |
specifies a specific postcondition for a callable entity; it shall be |
| 576 |
specified by an @nt{expression}, called a @i<specific postcondition |
| 577 |
expression>.@Defn{specific postcondition expression}@Defn2{Term=[postcondition expression],Sec=[specific]} |
| 578 |
If not specified for an entity, the specific postcondition |
| 579 |
expression for the entity is the enumeration literal True.@AspectDefn{Post}]} |
| 580 |
|
| 581 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Post], |
| 582 |
Text=[@ChgAdded{Version=[3],Text=[Postcondition; a condition that must hold |
| 583 |
true after a call.]}]} |
| 584 |
|
| 585 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]} |
| 586 |
@ChgAdded{Version=[3],Text=[Post'Class@\This aspect |
| 587 |
specifies a class-wide postcondition for an operation of a tagged type and its |
| 588 |
descendants; it shall be specified by an @nt{expression}, called a |
| 589 |
@i<class-wide postcondition expression>.@Defn{class-wide postcondition expression}@Defn2{Term=[postcondition expression],Sec=[class-wide]} |
| 590 |
If not specified for an entity, the class-wide postcondition |
| 591 |
expression for the entity is the enumeration literal True.@AspectDefn{Post'Class}]} |
| 592 |
@end{Description} |
| 593 |
|
| 594 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Post'Class], |
| 595 |
Text=[@ChgAdded{Version=[3],Text=[Postcondition inherited on type |
| 596 |
derivation.]}]} |
| 597 |
|
| 598 |
@begin{Resolution} |
| 599 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 600 |
@ChgAdded{Version=[3],Text=[The expected type for a precondition or |
| 601 |
postcondition expression is any boolean type.@PDefn2{Term=[expected type], |
| 602 |
Sec=(precondition expression)}@PDefn2{Term=[expected type], |
| 603 |
Sec=(postcondition expression)}]} |
| 604 |
|
| 605 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1]} |
| 606 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 607 |
@ChgAdded{Version=[3],Text=[Within the expression for a Pre'Class or Post'Class aspect for a primitive |
| 608 |
subprogram @Chg{Version=[4],New=[@i<S> ],Old=[]}of a tagged type @i<T>, a |
| 609 |
@Chg{Version=[4],New=[@nt<name>],Old=[name]} that denotes a formal parameter |
| 610 |
@Chg{Version=[4],New=[(or @i<S>'Result) ],Old=[]}of type |
| 611 |
@i<T> is interpreted as @Chg{Version=[4],New=[though it had a (notional) type |
| 612 |
@i<NT> that is a formal derived type whose ancestor type is @i<T>, with directly |
| 613 |
visible primitive operations],Old=[having type @i<T>'Class]}. Similarly, a |
| 614 |
@Chg{Version=[4],New=[@nt<name>],Old=[name]} that denotes a |
| 615 |
formal access parameter @Chg{Version=[4],New=[(or @i<S>'Result) ],Old=[]}of |
| 616 |
type access-to-@i<T> is interpreted as having type |
| 617 |
@Chg{Version=[4],New=[access-to-@i<NT>],Old=[access-to-@i<T>'Class]}. |
| 618 |
@Redundant[@Chg{Version=[4],New=[The result of this interpretation |
| 619 |
is that the only operations that can be applied to such @nt{name}s are those |
| 620 |
defined for such a formal derived type.],Old=[This ensures that the |
| 621 |
expression is well-defined for a primitive subprogram of a type descended |
| 622 |
from @i<T>.]}]]} |
| 623 |
|
| 624 |
@begin{Reason} |
| 625 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0159-1]} |
| 626 |
@ChgAdded{Version=[4],Text=[This ensures that the |
| 627 |
expression is well-defined for any primitive |
| 628 |
subprogram of a type descended from @i<T>.]} |
| 629 |
@end{Reason} |
| 630 |
|
| 631 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0264-1]} |
| 632 |
@ChgAdded{Version=[3],Text=[For an attribute_reference with attribute_designator |
| 633 |
Old, if the attribute reference has an expected type or shall resolve to a given |
| 634 |
type, the same applies to the @nt{prefix}; otherwise, the @nt{prefix} shall be |
| 635 |
resolved independently of context.]} |
| 636 |
|
| 637 |
@end{Resolution} |
| 638 |
|
| 639 |
@begin{Legality} |
| 640 |
|
| 641 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0230-1]} |
| 642 |
@ChgAdded{Version=[3],Text=[The Pre or Post aspect shall not be specified for an |
| 643 |
abstract subprogram or a null procedure. @Redundant[Only the Pre'Class and |
| 644 |
Post'Class aspects may be specified for such a subprogram.]]} |
| 645 |
|
| 646 |
@begin{Discussion} |
| 647 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 648 |
@ChgAdded{Version=[3],Text=[Pre'Class and Post'Class can only be specified |
| 649 |
on primitive routines of tagged types, by a blanket rule found in |
| 650 |
@RefSecNum{Aspect Specifications}.]} |
| 651 |
@end{Discussion} |
| 652 |
|
| 653 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 654 |
@ChgAdded{Version=[3],Type=[Leading],Text=[If a type @i<T> has an implicitly |
| 655 |
declared subprogram @i<P> inherited from a parent type @i<T1> and |
| 656 |
a homograph (see @RefSecNum{Visibility}) of @i<P> from a progenitor type |
| 657 |
@i<T2>, and]} |
| 658 |
|
| 659 |
@begin{Itemize} |
| 660 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 661 |
@ChgAdded{Version=[3],Text=[the corresponding primitive subprogram @i<P1> of |
| 662 |
type @i<T1> is neither null nor abstract; and]} |
| 663 |
|
| 664 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 665 |
@ChgAdded{Version=[3],Text=[the class-wide precondition expression True does |
| 666 |
not apply to @i<P1> (implicitly or explicitly); and]} |
| 667 |
|
| 668 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 669 |
@ChgAdded{Version=[3],Text=[there is a class-wide precondition expression that |
| 670 |
applies to the corresponding primitive subprogram @i<P2> of @i<T2> that does |
| 671 |
not fully conform to any class-wide precondition expression that applies to |
| 672 |
@i<P1>,]} |
| 673 |
@end{Itemize} |
| 674 |
|
| 675 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 676 |
@ChgAdded{Version=[3],Type=[Leading],Text=[then:]} |
| 677 |
|
| 678 |
@begin{Itemize} |
| 679 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 680 |
@ChgAdded{Version=[3],Text=[If the type @i<T> is abstract, the implicitly |
| 681 |
declared subprogram @i<P> is @i<abstract>.]} |
| 682 |
|
| 683 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 684 |
@ChgAdded{Version=[3],Text=[Otherwise, the subprogram @i<P> |
| 685 |
@i{requires overriding} and shall be overridden with a |
| 686 |
nonabstract subprogram.@PDefn{requires overriding}]} |
| 687 |
|
| 688 |
@begin{Discussion} |
| 689 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 690 |
@ChgAdded{Version=[3],Text=[We use the term "requires overriding" here so that |
| 691 |
this rule is taken into account when calculating visibility in |
| 692 |
@RefSecNum{Visibility}; otherwise we would have a mess when this routine is |
| 693 |
overridden.]} |
| 694 |
@end{Discussion} |
| 695 |
@end{Itemize} |
| 696 |
|
| 697 |
@begin{Reason} |
| 698 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 699 |
@ChgAdded{Version=[3],Text=[Such an inherited subprogram would necessarily |
| 700 |
violate the Liskov Substitutability Principle (LSP) if called via a |
| 701 |
dispatching call from an ancestor other than the one that provides the |
| 702 |
called body. In such a case, the class-wide precondition of the actual body |
| 703 |
is stronger than the class-wide precondition of the ancestor. If we did not |
| 704 |
enforce that precondition for the body, the body could be called when the |
| 705 |
precondition it knows about is False @em such "counterfeiting" of |
| 706 |
preconditions has to be avoided. But enforcing the precondition violates |
| 707 |
LSP. We do not want the language to be implicitly creating bodies that |
| 708 |
violate LSP; the programmer can still write an explicit body that calls the |
| 709 |
appropriate parent subprogram. In that case, the violation of LSP is |
| 710 |
explicitly in the code and obvious to code reviewers (both human and |
| 711 |
automated).]} |
| 712 |
|
| 713 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 714 |
@ChgAdded{Version=[3],Text=[We have to say that the subprogram is abstract for |
| 715 |
an abstract type in this case, so that the next concrete type has to |
| 716 |
override it for the reasons above. Otherwise, inserting an extra level of |
| 717 |
abstract types would eliminate the requirement to override (as there is only |
| 718 |
one declared operation for the concrete type), and that would be bad for the |
| 719 |
reasons given above.]} |
| 720 |
@end{Reason} |
| 721 |
|
| 722 |
@begin{Ramification} |
| 723 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 724 |
@ChgAdded{Version=[3],Text=[This requires the set of class-wide preconditions |
| 725 |
that apply to the interface routine to be strictly stronger than those that |
| 726 |
apply to the concrete routine. Since full conformance |
| 727 |
requires each name to denote the same declaration, it is unlikely that |
| 728 |
independently declared preconditions would conform. This rule does allow |
| 729 |
"diamond inheritance" of preconditions, and of course no preconditions at |
| 730 |
all match.]} |
| 731 |
|
| 732 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 733 |
@ChgAdded{Version=[3],Text=[We considered adopting a rule that would allow |
| 734 |
examples where the expressions would conform after all inheritance has been |
| 735 |
applied, but this is complex and is not likely to be common in practice. |
| 736 |
Since the penalty here is just that an explicit overriding is required, the |
| 737 |
complexity is too much.]} |
| 738 |
@end{Ramification} |
| 739 |
|
| 740 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0247-1]} |
| 741 |
@ChgAdded{Version=[3],Text=[If a renaming of a subprogram or entry @i<S1> |
| 742 |
overrides an inherited subprogram @i<S2>, then the overriding is illegal unless |
| 743 |
each class-wide precondition expression that applies to @i<S1> fully conforms to |
| 744 |
some class-wide precondition expression that applies to @i<S2> and each |
| 745 |
class-wide precondition expression that applies to @i<S2> fully conforms to some |
| 746 |
class-wide precondition expression that applies to @i<S1>.]} |
| 747 |
|
| 748 |
@begin{Reason} |
| 749 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 750 |
@ChgAdded{Version=[3],Text=[Such an overriding subprogram would violate LSP, |
| 751 |
as the precondition of @i<S1> would usually be different (and thus stronger) |
| 752 |
than the one known to a dispatching call through an ancestor routine of @i<S2>. |
| 753 |
This is always OK if the preconditions match, so we always allow that.]} |
| 754 |
@end{Reason} |
| 755 |
|
| 756 |
@begin{Ramification} |
| 757 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 758 |
@ChgAdded{Version=[3],Text=[This only applies to primitives of tagged types; |
| 759 |
other routines cannot have class-wide preconditions.]} |
| 760 |
@end{Ramification} |
| 761 |
|
| 762 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0131-1]} |
| 763 |
@ChgAdded{Version=[4],Text=[Pre'Class shall not be specified for an overriding |
| 764 |
primitive subprogram of a tagged type @i<T> unless the Pre'Class aspect is |
| 765 |
specified for the corresponding primitive subprogram of some ancestor of @i<T>.]} |
| 766 |
|
| 767 |
@begin{Reason} |
| 768 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 769 |
@ChgAdded{Version=[4],Text=[Any such Pre'Class will have no effect, as it |
| 770 |
will be @key[or]ed with True. As such, it is highly misleading for readers, |
| 771 |
especially for those who are determining the assumptions that can |
| 772 |
be made in the body of the primitive subprogram. Note that in this |
| 773 |
case there is nothing explicit that might indicate that the |
| 774 |
class-wide precondition is ineffective. This rule does not prevent |
| 775 |
explicitly writing an ineffective class-wide precondition (for |
| 776 |
instance, if the parent subprogram has explicitly specified a |
| 777 |
precondition of True).]} |
| 778 |
@end{Reason} |
| 779 |
|
| 780 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0131-1]} |
| 781 |
@ChgAdded{Version=[4],Text=[@PDefn{generic contract issue} |
| 782 |
In addition to the places where |
| 783 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 784 |
these rules also apply in the private part of an instance of a generic unit.]} |
| 785 |
@end{Legality} |
| 786 |
|
| 787 |
@begin{StaticSem} |
| 788 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 789 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0131-1]} |
| 790 |
@ChgAdded{Version=[4],Type=[Leading],Text=[]}@Comment{Conditional Leading} |
| 791 |
@ChgAdded{Version=[3],Text=[If a Pre'Class or Post'Class aspect is specified for |
| 792 |
a primitive subprogram @Chg{Version=[4],New=[@i<S> ],Old=[]}of a tagged type |
| 793 |
@i<T>, @Chg{Version=[4],New=[or such an aspect defaults to True, ],Old=[]}then |
| 794 |
@Chg{Version=[4],New=[a corresponding],Old=[the associated]} expression |
| 795 |
also applies to the corresponding primitive subprogram |
| 796 |
@Chg{Version=[4],New=[@i<S> ],Old=[]}of each descendant of |
| 797 |
@i<T>.@Chg{Version=[4],New=[ The @i<corresponding expression> is constructed |
| 798 |
from the associated expression as follows:@Defn2{Term=[corresponding expresssion],Sec=[class-wide precondition]} |
| 799 |
@Defn2{Term=[corresponding expresssion],Sec=[class-wide postcondition]}],Old=[]}]} |
| 800 |
|
| 801 |
@begin{Ramification} |
| 802 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 803 |
@ChgAdded{Version=[4],Text=[A Pre'Class defaults to True only if no class-wide |
| 804 |
preconditions are inherited for the subprogram. The same is true for |
| 805 |
Post'Class.]} |
| 806 |
@end{Ramification} |
| 807 |
|
| 808 |
@begin{Reason} |
| 809 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 810 |
@ChgAdded{Version=[4],Text=[We have to inherit precondition expressions that |
| 811 |
default to True, so that later overridings don't strengthen the |
| 812 |
precondition (a violation of LSP). We do the same for postconditions |
| 813 |
for consistency.]} |
| 814 |
@end{Reason} |
| 815 |
|
| 816 |
@begin{Itemize} |
| 817 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0113-1]} |
| 818 |
@ChgAdded{Version=[4],Text=[References to formal parameters of @i<S> (or to |
| 819 |
@i<S> itself) are replaced with references to the corresponding formal |
| 820 |
parameters of the corresponding inherited or overriding subprogram |
| 821 |
@i<S> (or to the corresponding subprogram @i<S> itself).]} |
| 822 |
|
| 823 |
@begin{Reason} |
| 824 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 825 |
@ChgAdded{Version=[4],Text=[We have to define the corresponding expression |
| 826 |
this way as overriding routines are only required to be subtype conformant; in |
| 827 |
particular, the parameter names can be different. So we have to talk about |
| 828 |
corresponding parameters without mentioning any names.]} |
| 829 |
@end{Reason} |
| 830 |
@end{Itemize} |
| 831 |
|
| 832 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0113-1]} |
| 833 |
@ChgAdded{Version=[4],Text=[The primitive subprogram @i<S> is illegal if it is |
| 834 |
not abstract and the corresponding expression for a Pre'Class or Post'Class |
| 835 |
aspect would be illegal.]} |
| 836 |
|
| 837 |
@begin{Ramification} |
| 838 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 839 |
@ChgAdded{Version=[4],Text=[This can happen, for instance, if one of the |
| 840 |
subprograms called in the corresponding expression is abstract. We made the |
| 841 |
rule general so that we don't have to worry about exactly which cases |
| 842 |
can cause this to happen, both now and in the future.]} |
| 843 |
@end{Ramification} |
| 844 |
|
| 845 |
@begin{Reason} |
| 846 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 847 |
@ChgAdded{Version=[4],Text=[We allow illegal corresponding expressions |
| 848 |
on abstract subprograms as they could never be evaluated, and we need to |
| 849 |
allow such expressions to contain calls to abstract subprograms.]} |
| 850 |
@end{Reason} |
| 851 |
|
| 852 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1],ARef=[AI05-0290-1]} |
| 853 |
@ChgAdded{Version=[3],Text=[If performing checks is required by the Pre, |
| 854 |
Pre'Class, Post, or Post'Class assertion policies (see |
| 855 |
@RefSecNum{Pragmas Assert and Assertion_Policy}) in effect at the point of a |
| 856 |
corresponding aspect specification applicable to a given subprogram or entry, |
| 857 |
then the respective precondition or postcondition expressions are considered |
| 858 |
@i<enabled>.@Defn2{Term=[enabled],Sec=[precondition expression]}@Defn2{Term=[enabled],Sec=[postcondition expression]}]} |
| 859 |
|
| 860 |
@begin{Ramification} |
| 861 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0290-1]} |
| 862 |
@ChgAdded{Version=[3],Text=[If a class-wide precondition or postcondition |
| 863 |
expression is enabled, it remains enabled when inherited by an overriding |
| 864 |
subprogram, even if the policy |
| 865 |
in effect is Ignore for the inheriting subprogram.]} |
| 866 |
@end{Ramification} |
| 867 |
|
| 868 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0273-1]} |
| 869 |
@ChgAdded{Version=[3],Type=[Leading],Text=[An @nt{expression} is |
| 870 |
@i{potentially unevaluated} if it occurs within:@Defn{potentially unevaluated expression}]} |
| 871 |
|
| 872 |
@begin{Itemize} |
| 873 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 874 |
@ChgAdded{Version=[3],Text=[any part of an @nt{if_expression} other than the |
| 875 |
first @nt{condition};]} |
| 876 |
|
| 877 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 878 |
@ChgAdded{Version=[3],Text=[a @SynI{dependent_}@nt{expression} of a |
| 879 |
@nt{case_expression};]} |
| 880 |
|
| 881 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 882 |
@ChgAdded{Version=[4],Text=[a @nt{predicate} of a |
| 883 |
@nt{quantified_expression};]} |
| 884 |
|
| 885 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 886 |
@ChgAdded{Version=[3],Text=[the right operand of a short-circuit control |
| 887 |
form; or]} |
| 888 |
|
| 889 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 890 |
@ChgAdded{Version=[3],Text=[a @nt{membership_choice} other than the first |
| 891 |
of a membership operation.]} |
| 892 |
@end{Itemize} |
| 893 |
|
| 894 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 895 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} X that |
| 896 |
denotes an object of a nonlimited type}, the following attribute is defined:]} |
| 897 |
@begin(description) |
| 898 |
@ChgNote{For Version=[3], Kind=[AddedNormal].} |
| 899 |
@ChgAttribute{Version=[4],Kind=[Revised],ChginAnnex=[T], |
| 900 |
Leading=<F>, Prefix=<X>, AttrName=<Old>, ARef=[AI05-0145-2], ARef=[AI05-0262-1], ARef=[AI05-0273-1], ARef=[AI12-0032-1], |
| 901 |
InitialVersion=[3],Text=[@Chg{Version=[3],New=[@Chg{Version=[4],New=[Each],Old=[For each]} |
| 902 |
X'Old in a postcondition expression that |
| 903 |
is enabled@Chg{Version=[4],New=[ denotes],Old=[,]} a constant |
| 904 |
@Chg{Version=[4],New=[that ],Old=[]}is implicitly |
| 905 |
declared at the beginning of the subprogram |
| 906 |
@Chg{Version=[4],New=[body,],Old=[or]} |
| 907 |
entry@Chg{Version=[4],New=[ body, or accept statement],Old=[]}.@Chg{Version=[4],New=[],Old=[ |
| 908 |
The constant is of the type of X and is initialized to the result |
| 909 |
of evaluating X (as an expression) at the point of the constant declaration. |
| 910 |
The value of X'Old in the postcondition expression is the value of this |
| 911 |
constant; the type of X'Old is the type of X. These implicit constant |
| 912 |
declarations occur in an |
| 913 |
arbitrary order.@PDefn2{Term=[arbitrary order],Sec=[allowed]}]}],Old=[]}]}@Comment{End of Annex text here.} |
| 914 |
|
| 915 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1],ARef=[AI12-0159-1]} |
| 916 |
@ChgAdded{Version=[4],Type=[Leading],NoPrefix=[T],Text=[The implicitly declared |
| 917 |
entity denoted by each occurrence of X'Old is declared as follows:]} |
| 918 |
|
| 919 |
@begin{Itemize} |
| 920 |
@ChgRef{Version=[4],Kind=[Added]} |
| 921 |
@ChgAdded{Version=[4],Type=[Leading],Text=[If X is of an anonymous access |
| 922 |
type defined by an @nt{access_definition} @i<A> then]} |
| 923 |
@begin{ChildExample} |
| 924 |
@ChgRef{Version=[4],Kind=[Added]} |
| 925 |
@ChgAdded{Version=[4],Text=[@i<X'Old> : @key[constant] @i<A> := X;]} |
| 926 |
@end{ChildExample} |
| 927 |
|
| 928 |
@ChgRef{Version=[4],Kind=[Added]} |
| 929 |
@ChgAdded{Version=[4],Type=[Leading],Text=[If X is of a specific tagged type @i<T> then]} |
| 930 |
@begin{ChildExample} |
| 931 |
@ChgRef{Version=[4],Kind=[Added]} |
| 932 |
@ChgAdded{Version=[4],Text=[@examcom<anonymous> : @key[constant] @i<T>'Class := @i<T>'Class(X); |
| 933 |
@i<X'Old> : @i<T> @key[renames] @i<T>(@examcom<anonymous>);]} |
| 934 |
@end{ChildExample} |
| 935 |
@ChgRef{Version=[4],Kind=[Added]} |
| 936 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[where the name X'Old denotes |
| 937 |
the object renaming.]} |
| 938 |
@begin{Ramification} |
| 939 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 940 |
@ChgAdded{Version=[4],Text=[This means that the underlying tag associated |
| 941 |
with X'Old is that of X and not that of the nominal type of X.]} |
| 942 |
@end{Ramification} |
| 943 |
|
| 944 |
@ChgRef{Version=[4],Kind=[Added]} |
| 945 |
@ChgAdded{Version=[4],Type=[Leading],Text=[Otherwise]} |
| 946 |
@begin{ChildExample} |
| 947 |
@ChgRef{Version=[4],Kind=[Added]} |
| 948 |
@ChgAdded{Version=[4],Text=[@i<X'Old> : @key[constant] @i<S> := X;]} |
| 949 |
@end{ChildExample} |
| 950 |
@ChgRef{Version=[4],Kind=[Added]} |
| 951 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[where @i<S> is the nominal subtype |
| 952 |
of X. This includes the case where the type of @i<S> is an anonymous array |
| 953 |
type or a universal type.]} |
| 954 |
@end{Itemize} |
| 955 |
|
| 956 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 957 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[The nominal subtype of X'Old is as |
| 958 |
implied by the above definitions. The expected type of the prefix of an Old |
| 959 |
attribute is that of the attribute. Similarly, if an Old attribute shall |
| 960 |
resolve to be of some type, then the prefix of the attribute shall resolve to |
| 961 |
be of that type.]} |
| 962 |
|
| 963 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2], ARef=[AI05-0262-1], ARef=[AI05-0273-1]} |
| 964 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[Reference to this attribute is only |
| 965 |
allowed within a postcondition expression. The @nt{prefix} of an Old |
| 966 |
@nt{attribute_reference} shall not contain a Result @nt{attribute_reference}, |
| 967 |
nor an Old @nt{attribute_reference}, nor a use of an entity declared within |
| 968 |
the postcondition expression but not within @nt{prefix} itself (for example, |
| 969 |
the loop parameter of an enclosing @nt{quantified_expression}). |
| 970 |
The @nt{prefix} of an Old @nt{attribute_reference} that is |
| 971 |
potentially unevaluated shall statically denote an entity.]} |
| 972 |
|
| 973 |
@begin{Discussion} |
| 974 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 975 |
@ChgAdded{Version=[3],Text=<The @nt{prefix} X can be any |
| 976 |
nonlimited object that obeys the syntax for prefix other than the few |
| 977 |
exceptions given above (discussed below). Useful cases are: the @nt{name} |
| 978 |
of a formal parameter of mode [@key[in]] @key[out], the @nt{name} of a global |
| 979 |
variable updated by the subprogram, a function call passing those as |
| 980 |
parameters, a subcomponent of those things, etc.>} |
| 981 |
|
| 982 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 983 |
@ChgAdded{Version=[3],Text=[A qualified expression can be used to make an |
| 984 |
arbitrary expression into a valid prefix, so T'(X + Y)'Old is legal, even |
| 985 |
though (X + Y)'Old is not. The value being saved here is the sum of X and Y (a |
| 986 |
function result is an object). Of course, in this case "+"(X, Y)'Old is also |
| 987 |
legal, but the qualified expression is arguably more readable.]} |
| 988 |
|
| 989 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 990 |
@ChgAdded{Version=[3],Text=[Note that F(X)'Old and F(X'Old) are not |
| 991 |
necessarily equal. The former calls F(X) and saves that value for later use |
| 992 |
during the postcondition. The latter saves the value of X, and during the |
| 993 |
postcondition, passes that saved value to F. In most cases, the former is what |
| 994 |
one wants (but it is not always legal, see below).]} |
| 995 |
|
| 996 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 997 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0032-1]} |
| 998 |
@ChgAdded{Version=[3],Text=[If X has controlled parts, adjustment and |
| 999 |
finalization are implied by the implicit constant |
| 1000 |
declaration.@Chg{Version=[4],New=[ Similarly, the implicit constant |
| 1001 |
declaration defines the accessibility level of X'Old.],Old=[]}]} |
| 1002 |
|
| 1003 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1004 |
@ChgAdded{Version=[3],Text=[If postconditions are disabled, we want the |
| 1005 |
compiler to avoid any overhead associated with saving 'Old values.]} |
| 1006 |
|
| 1007 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1008 |
@ChgAdded{Version=[3],Text=['Old makes no sense for limited types, because its |
| 1009 |
implementation involves copying. It might make semantic sense to allow |
| 1010 |
build-in-place, but it's not worth the trouble.]} |
| 1011 |
@end{Discussion} |
| 1012 |
|
| 1013 |
@begin{Reason} |
| 1014 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0273-1]} |
| 1015 |
@ChgAdded{Version=[3],Text=[Since the @nt{prefix} is evaluated unconditionally |
| 1016 |
when the subprogram is called, we cannot allow it to include values that do |
| 1017 |
not exist at that time (like 'Result and loop parameters of @nt{quantified_expression}s). |
| 1018 |
We also do not allow it to include 'Old references, as those would be |
| 1019 |
redundant (the entire @nt{prefix} is evaluated when the subprogram is called), |
| 1020 |
and allowing them would require some sort of order to the implicit constant |
| 1021 |
declarations (because in A(I'Old)'Old, we surely would want the value of |
| 1022 |
I'Old evaluated before the A(I'Old) is evaluated).]} |
| 1023 |
|
| 1024 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0273-1]} |
| 1025 |
@ChgAdded{Version=[3],Type=[Leading],Text=[In addition, we only allow simple names as the |
| 1026 |
@nt{prefix} of the Old attribute if the @nt{attribute_reference} might not |
| 1027 |
be evaluated when the postcondition expression is evaluated. This is necessary because |
| 1028 |
the Old @nt{prefix}es have to be unconditionally evaluated when the subprogram |
| 1029 |
is called; the compiler cannot in general know whether they will be needed |
| 1030 |
in the postcondition expression. To see the problem, consider:]} |
| 1031 |
|
| 1032 |
@begin{Example} |
| 1033 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1034 |
@ChgAdded{Version=[3],Text=[Table : @key[array] (1..10) @key[of] Integer := ... |
| 1035 |
@key[procedure] Bar (I : @key[in out] Natural) |
| 1036 |
@key[with] Post => I > 0 @key[and then] Table(I)'Old = 1; -- @Examcom{Illegal}]} |
| 1037 |
@end{Example} |
| 1038 |
|
| 1039 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1040 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[In this example, the compiler |
| 1041 |
cannot know the value of I when the subprogram returns (since the subprogram |
| 1042 |
execution can change it), and thus it does not know whether Table(I)'Old will |
| 1043 |
be needed then. Thus it has to always create an implicit constant |
| 1044 |
and evaluate Table(I) when Bar is called (because not having the value when |
| 1045 |
it is needed is not acceptable). But if I = 0 when the subprogram is called, |
| 1046 |
that evaluation will raise Constraint_Error, and that will happen even if I |
| 1047 |
is unchanged by the subprogram and the value of Table(I)'Old is not ultimately |
| 1048 |
needed. It's easy to see how a similar problem could occur for a dereference |
| 1049 |
of an access type. This would be mystifying (since the point of the short |
| 1050 |
circuit is to eliminate this possibility, but it cannot do so). Therefore, we |
| 1051 |
require the @nt{prefix} of any Old attribute in such a context to statically |
| 1052 |
denote an object, which eliminates anything that could change at during |
| 1053 |
execution.]} |
| 1054 |
|
| 1055 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1056 |
@ChgAdded{Version=[3],Text=[It is easy to work around most errors that occur |
| 1057 |
because of this rule. Just move the 'Old to the outer object, before any |
| 1058 |
indexing, dereferences, or components. (That does not work for function calls, |
| 1059 |
however, nor does it work for array indexing if the index can change during |
| 1060 |
the execution of the subprogram.)]} |
| 1061 |
@end{Reason} |
| 1062 |
|
| 1063 |
@begin{Ramification} |
| 1064 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1065 |
@ChgAdded{Version=[4],Type=[Leading],Text=[An accept statement for a task |
| 1066 |
entry with enabled postconditions such as]} |
| 1067 |
@begin{Example} |
| 1068 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1069 |
@ChgAdded{Version=[4],Text=[@key[accept] E @key[do] |
| 1070 |
@examcom<statements> |
| 1071 |
@key[exception] |
| 1072 |
@examcom<handlers> |
| 1073 |
@key[end];]} |
| 1074 |
@end{Example} |
| 1075 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1076 |
@ChgAdded{Version=[4],Type=[Leading],Text=[behaves (at runtime) as follows:]} |
| 1077 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 1078 |
@begin{Example} |
| 1079 |
@ChgAdded{Version=[4],Text=[@key[accept] E @key[do] |
| 1080 |
@key[declare] |
| 1081 |
@examcom<declarations, if any, of 'Old constants> |
| 1082 |
@key[begin] |
| 1083 |
@key[begin] |
| 1084 |
@examcom<statements> |
| 1085 |
@key[exception] |
| 1086 |
@examcom<handlers> |
| 1087 |
@key[end]; |
| 1088 |
@examcom<postcondition checks> |
| 1089 |
@key[end]; |
| 1090 |
@key[end];]} |
| 1091 |
@end{Example} |
| 1092 |
|
| 1093 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1094 |
@ChgAdded{Version=[4],Text=[Preconditions are checked by the caller before the |
| 1095 |
rendezvous begins. Postcondition expressions might, of course, reference 'Old |
| 1096 |
constants.]} |
| 1097 |
|
| 1098 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1099 |
@ChgAdded{Version=[4],Text=[In the case of a protected operation with |
| 1100 |
enabled postconditions, 'Old constant declarations (if any) are |
| 1101 |
elaborated after the start of the protected action. Postcondition checks |
| 1102 |
(which might reference these constants) are performed before the end of |
| 1103 |
the protected action as described below.]} |
| 1104 |
@end{Ramification} |
| 1105 |
@end(description) |
| 1106 |
@EndPrefixType{} |
| 1107 |
|
| 1108 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2]} |
| 1109 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For @PrefixType{a @nt{prefix} F that |
| 1110 |
denotes a function declaration}, the following attribute is defined:]} |
| 1111 |
@begin(description) |
| 1112 |
@ChgAttribute{Version=[3],Kind=[AddedNormal],ChginAnnex=[T], |
| 1113 |
Leading=<F>, Prefix=<F>, AttrName=<Result>, ARef=[AI05-0145-2], ARef=[AI05-0262-1], |
| 1114 |
InitialVersion=[3], |
| 1115 |
Text=[@Chg{Version=[3],New=[Within a postcondition expression for function F, |
| 1116 |
denotes the result object of the function. The type of this attribute is that |
| 1117 |
of the function result except within a Post'Class postcondition expression for |
| 1118 |
a function with a controlling result or with a controlling access result. For |
| 1119 |
a controlling result, the type of the attribute is @i<T>'Class, where @i<T> is |
| 1120 |
the function result type. For a controlling access result, the type of the |
| 1121 |
attribute is an anonymous access type whose designated type is @i<T>'Class, |
| 1122 |
where @i<T> is the designated type of the function result type.],Old=[]}]}@Comment{End of Annex text here.} |
| 1123 |
|
| 1124 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0262-1]} |
| 1125 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[Use of this |
| 1126 |
attribute is allowed only within a postcondition expression |
| 1127 |
for F.]} |
| 1128 |
@end(description) |
| 1129 |
@EndPrefixType{} |
| 1130 |
@end{StaticSem} |
| 1131 |
|
| 1132 |
@begin{Runtime} |
| 1133 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0290-1]} |
| 1134 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Upon a call of the subprogram or |
| 1135 |
entry, after evaluating any actual parameters, precondition checks are performed |
| 1136 |
as follows:]} |
| 1137 |
|
| 1138 |
@begin{Itemize} |
| 1139 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1140 |
@ChgAdded{Version=[3],Text=[The specific precondition check begins with the |
| 1141 |
evaluation of the specific precondition expression that applies to the |
| 1142 |
subprogram or entry, if it is enabled; if the expression evaluates to False, |
| 1143 |
Assertions.Assertion_Error is raised; if the expression is not enabled, |
| 1144 |
the check succeeds.@Defn2{Term=(Assertion_Error), |
| 1145 |
Sec=(raised by failure of run-time check)}@Defn2{Term=[check, language-defined], |
| 1146 |
Sec=[controlled by assertion policy]}@Defn2{Term=[precondition check],Sec=[specific]}]} |
| 1147 |
|
| 1148 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1149 |
@ChgAdded{Version=[3],Text=[The class-wide precondition check begins with the |
| 1150 |
evaluation of any enabled class-wide precondition expressions that apply |
| 1151 |
to the subprogram or entry. If and only if all the class-wide precondition |
| 1152 |
expressions evaluate to False, Assertions.Assertion_Error is raised.@Defn2{Term=(Assertion_Error), |
| 1153 |
Sec=(raised by failure of run-time check)}@Defn2{Term=[check, language-defined], |
| 1154 |
Sec=[controlled by assertion policy]}@Defn2{Term=[precondition check],Sec=[class-wide]}]} |
| 1155 |
|
| 1156 |
@begin{Ramification} |
| 1157 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1158 |
@ChgAdded{Version=[3],Text=[The class-wide precondition expressions of the |
| 1159 |
entity itself as well as those of any parent or progenitor operations are |
| 1160 |
evaluated, as these expressions apply to the corresponding operations |
| 1161 |
of all descendants.]} |
| 1162 |
|
| 1163 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1164 |
@ChgAdded{Version=[3],Text=[Class-wide precondition checks are performed for |
| 1165 |
all appropriate calls, but only enabled precondition expressions are |
| 1166 |
evaluated. Thus, the check would be trivial if no precondition expressions |
| 1167 |
are enabled.]} |
| 1168 |
@end{Ramification} |
| 1169 |
@end{Itemize} |
| 1170 |
|
| 1171 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0269-1]} |
| 1172 |
@ChgAdded{Version=[3],Text=[The precondition checks are performed in an |
| 1173 |
arbitrary order, |
| 1174 |
and if any of the class-wide precondition expressions evaluate to True, it is |
| 1175 |
not specified whether the other class-wide precondition expressions are |
| 1176 |
evaluated. The precondition checks and any check for elaboration of the |
| 1177 |
subprogram body are performed in an arbitrary order. It is not |
| 1178 |
specified whether in a call on a protected operation, the checks are performed |
| 1179 |
before or after starting the protected action. For an entry |
| 1180 |
call, the checks are performed prior to checking whether the entry is open.@PDefn2{Term=(arbitrary order), |
| 1181 |
Sec=(allowed)}@PDefn{unspecified}]} |
| 1182 |
|
| 1183 |
@begin{Reason} |
| 1184 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1185 |
@ChgAdded{Version=[3],Text=[We need to explicitly allow short-circuiting |
| 1186 |
of the evaluation of the class-wide precondition check if any expression |
| 1187 |
fails, as it consists of multiple expressions; we don't need a similar |
| 1188 |
permission for the specific precondition check as it consists only of a |
| 1189 |
single expression. Nothing is evaluated for the call after a check fails, |
| 1190 |
as the failed check propagates an exception.]} |
| 1191 |
@end{Reason} |
| 1192 |
|
| 1193 |
|
| 1194 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0262-1],ARef=[AI05-0290-1]} |
| 1195 |
@ChgAdded{Version=[3],Text=[Upon successful return from a call of the subprogram |
| 1196 |
or entry, prior to copying back any by-copy @key[in out] |
| 1197 |
or @key[out] parameters, the postcondition check is performed. This consists of |
| 1198 |
the evaluation of any enabled specific and class-wide postcondition expressions that |
| 1199 |
apply to the subprogram or entry. If any of the postcondition expressions |
| 1200 |
evaluate to False, then Assertions.Assertion_Error is raised. The |
| 1201 |
postcondition expressions are evaluated in an arbitrary order, and if any |
| 1202 |
postcondition expression evaluates to False, it is not specified whether any |
| 1203 |
other postcondition expressions are evaluated. The postcondition check, and any |
| 1204 |
constraint or predicate checks associated with |
| 1205 |
@key[in out] or @key[out] parameters are performed in |
| 1206 |
an arbitrary order.@Defn{postcondition check}@Defn2{Term=[check, language-defined], |
| 1207 |
Sec=[controlled by assertion policy]}@Defn2{Term=(Assertion_Error), |
| 1208 |
Sec=(raised by failure of run-time check)}@PDefn2{Term=(arbitrary order), |
| 1209 |
Sec=(allowed)}@PDefn{unspecified}]} |
| 1210 |
|
| 1211 |
@begin{Ramification} |
| 1212 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1213 |
@ChgAdded{Version=[3],Text=[The class-wide postcondition expressions of the |
| 1214 |
entity itself as well as those of any parent or progenitor operations are |
| 1215 |
evaluated, as these apply to all descendants; in contrast, only the specific |
| 1216 |
postcondition of the entity applies. Postconditions can always be evaluated |
| 1217 |
inside the invoked body.]} |
| 1218 |
@end{Ramification} |
| 1219 |
|
| 1220 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 1221 |
@ChgAdded{Version=[4],Text=[For a call to a task entry, the postcondition check |
| 1222 |
is performed before the end of the rendezvous; for a call to a protected |
| 1223 |
operation, the postcondition check is performed before the end of the protected |
| 1224 |
action of the call. The postcondition check for any call is performed before the |
| 1225 |
finalization of any implicitly-declared constants associated (as described |
| 1226 |
above) with Old @nt{attribute_reference}s but after the finalization of any |
| 1227 |
other entities whose accessibility level is that of the execution of the |
| 1228 |
callable construct.]} |
| 1229 |
@begin{Reason} |
| 1230 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0032-1]} |
| 1231 |
@ChgAdded{Version=[4],Text=[If a postcondition references the implicitly-declared constant associated |
| 1232 |
with an Old attribute, the postcondition must be evaluated before the |
| 1233 |
constant is finalized. One way to think of this is to imagine |
| 1234 |
declaring a controlled object between any implicit "'Old" |
| 1235 |
constant declarations and any explicit declarations, then |
| 1236 |
performing postcondition checks during the finalization of |
| 1237 |
this object.]} |
| 1238 |
@end{Reason} |
| 1239 |
|
| 1240 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1]} |
| 1241 |
@ChgAdded{Version=[3],Text=[If a precondition or postcondition check fails, the |
| 1242 |
exception is raised at the point of the call@Redundant[; the exception cannot |
| 1243 |
be handled inside the called subprogram or entry]. Similarly, any exception |
| 1244 |
raised by the evaluation of a precondition or postcondition expression is |
| 1245 |
raised at the point of call.]} |
| 1246 |
|
| 1247 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0262-1]} |
| 1248 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 1249 |
@ChgAdded{Version=[3],Text=[For any@Chg{Version=[4],New=[ call to a],Old=[]} |
| 1250 |
subprogram or entry @Chg{Version=[4],New=[@i<S>],Old=[call]} (including |
| 1251 |
dispatching calls), the checks |
| 1252 |
that are performed to verify specific precondition expressions and specific |
| 1253 |
and class-wide postcondition expressions are determined by those for the subprogram |
| 1254 |
or entry actually invoked. Note that the class-wide postcondition expressions |
| 1255 |
verified by the postcondition check that is part of a call on a primitive |
| 1256 |
subprogram of type @i<T> includes all class-wide postcondition expressions |
| 1257 |
originating in any progenitor of @i<T>@Redundant[, even if the primitive |
| 1258 |
subprogram called is inherited from a type @i<T1> and some of the postcondition |
| 1259 |
expressions do not apply to the corresponding primitive subprogram of |
| 1260 |
@i<T1>].@Chg{Version=[4],New=[ Any operations within a class-wide |
| 1261 |
postcondition expression that were resolved as primitive operations of the |
| 1262 |
(notional) formal derived type @i<NT>, are in the evaluation of the |
| 1263 |
postcondition bound to the corresponding operations of the type identified |
| 1264 |
by the controlling tag of the call on @i<S>.@Redundant[ This applies to both |
| 1265 |
dispatching and non-dispatching calls on @i<S>.]],Old=[]}]} |
| 1266 |
|
| 1267 |
@begin{Ramification} |
| 1268 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1269 |
@ChgAdded{Version=[3],Text=[This applies to access-to-subprogram calls, |
| 1270 |
dispatching calls, and to statically bound calls. We need this rule to cover |
| 1271 |
statically bound calls as well, as specific pre- and postconditions are not |
| 1272 |
inherited, but the subprogram might be.]} |
| 1273 |
|
| 1274 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1275 |
@ChgAdded{Version=[3],Text=[For concrete subprograms, we require the original |
| 1276 |
specific postcondition to be evaluated as well as the inherited class-wide |
| 1277 |
postconditions in order that the semantics of an explicitly defined wrapper |
| 1278 |
that does nothing but call the original subprogram is the same as that of |
| 1279 |
an inherited subprogram.]} |
| 1280 |
|
| 1281 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1282 |
@ChgAdded{Version=[3],Text=[Note that this rule does not apply to class-wide |
| 1283 |
preconditions; they have their own rules mentioned below.]} |
| 1284 |
@end{Ramification} |
| 1285 |
|
| 1286 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 1287 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 1288 |
@ChgAdded{Version=[3],Text=[The class-wide precondition check for a call to a |
| 1289 |
subprogram or entry @Chg{Version=[4],New=[@i<S> ],Old=[]}consists solely of |
| 1290 |
checking the class-wide precondition expressions that apply to the denoted |
| 1291 |
callable entity (not necessarily @Chg{Version=[4],New=[to ],Old=[]}the one |
| 1292 |
that is invoked).@Chg{Version=[4],New=[ Any operations within |
| 1293 |
such an expression that were resolved as primitive operations of the |
| 1294 |
(notional) formal derived type @i<NT> are in the evaluation of the |
| 1295 |
precondition bound to the corresponding operations of the type |
| 1296 |
identified by the controlling tag of the call on @i<S>.@Redundant[ This |
| 1297 |
applies to both dispatching and non-dispatching calls on @i<S>.]],Old=[]}]} |
| 1298 |
|
| 1299 |
@begin{Ramification} |
| 1300 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1301 |
@ChgAdded{Version=[3],Text=[For a dispatching call, we are talking about the |
| 1302 |
Pre'Class(es) that apply to the subprogram that the dispatching call is |
| 1303 |
resolving to, not the Pre'Class(es) for the subprogram that is ultimately |
| 1304 |
dispatched to. The class-wide precondition of the resolved call is |
| 1305 |
necessarily the same or stronger than that of the invoked call. For a |
| 1306 |
statically bound call, these are the same; for an access-to-subprogram, |
| 1307 |
(which has no class-wide preconditions of its own), we check the |
| 1308 |
class-wide preconditions of the invoked routine.]} |
| 1309 |
@end{Ramification} |
| 1310 |
|
| 1311 |
@begin{ImplNote} |
| 1312 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1313 |
@ChgAdded{Version=[3],Text=[These rules imply that logically, class-wide |
| 1314 |
preconditions of routines must be checked at the point of call (other |
| 1315 |
than for access-to-subprogram calls, which must be checked in the body, |
| 1316 |
probably using a wrapper). Specific preconditions that might be called with |
| 1317 |
a dispatching call or via an access-to-subprogram value must be checked |
| 1318 |
inside of the subprogram body. In contrast, the postcondition checks always |
| 1319 |
need to be checked inside the body of the routine. Of course, an |
| 1320 |
implementation can evaluate all of these at the point of call for statically |
| 1321 |
bound calls if the implementation uses wrappers for dispatching bodies and |
| 1322 |
for 'Access values.]} |
| 1323 |
|
| 1324 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 1325 |
@ChgAdded{Version=[3],Text=[There is no requirement for an implementation |
| 1326 |
to generate special code for routines that are imported from outside of |
| 1327 |
the Ada program. That's because there is a requirement on the programmer |
| 1328 |
that the use of interfacing aspects do not violate Ada semantics (see |
| 1329 |
@RefSecNum{Interfacing Aspects}). That includes making pre- and |
| 1330 |
postcondition checks. For instance, if the implementation expects routines |
| 1331 |
to make their own postcondition checks in the body before returning, |
| 1332 |
C code can be assumed to do this |
| 1333 |
(even though that is highly unlikely). That's even though the formal |
| 1334 |
definition of those checks is that they are evaluated at the call site. |
| 1335 |
Note that pre- and postconditions can be very useful for verification |
| 1336 |
tools (even if they aren't checked), because they tell the tool about the |
| 1337 |
expectations on the foreign code that it most likely cannot analyze.]} |
| 1338 |
@end{ImplNote} |
| 1339 |
|
| 1340 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0247-1],ARef=[AI05-0254-1]} |
| 1341 |
@ChgAdded{Version=[3],Text=[For a call via an access-to-subprogram value, all |
| 1342 |
precondition and postcondition checks performed are determined by the subprogram |
| 1343 |
or entry denoted by the prefix of the Access attribute reference that produced |
| 1344 |
the value.]} |
| 1345 |
@end{Runtime} |
| 1346 |
|
| 1347 |
@begin{Notes} |
| 1348 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0262-1]} |
| 1349 |
@ChgAdded{Version=[3],Text=[A precondition is checked just before the call. If |
| 1350 |
another task can change any value that the precondition expression depends on, |
| 1351 |
the precondition need not hold within the subprogram or entry body.]} |
| 1352 |
@end{Notes} |
| 1353 |
|
| 1354 |
@begin{Extend2005} |
| 1355 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0145-2],ARef=[AI05-0230-1],ARef=[AI05-0247-1],ARef=[AI05-0254-1],ARef=[AI05-0262-1],ARef=[AI05-0273-1],ARef=[AI05-0274-1]} |
| 1356 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 1357 |
Pre and Post aspects are new.]} |
| 1358 |
@end{Extend2005} |
| 1359 |
|
| 1360 |
@begin{Inconsistent2012} |
| 1361 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0032-1]} |
| 1362 |
@ChgAdded{Version=[4],Text=[@Defn{inconsistencies with Ada 2012}@b<Corrigendum:> |
| 1363 |
The Old attribute is defined more carefully. This changes the nominal subtype |
| 1364 |
and place of declaration of the attribute compared to the published Ada 2012 |
| 1365 |
Standard. In extreme cases, this could change the runtime behavior of the |
| 1366 |
attribute (for instance, the tag might be different). The changes are most |
| 1367 |
likely going to prevent bugs by being more intuitive, but it is possible that |
| 1368 |
a program that previously worked might fail.]} |
| 1369 |
|
| 1370 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0113-1],ARef=[AI12-0159-1]} |
| 1371 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Eliminated unintentional |
| 1372 |
redispatching from class-wide preconditions and postconditions. This means |
| 1373 |
that a different body might be evaluated for a statically bound call to a |
| 1374 |
routine that has a class-wide precondition or postcondition. The change means |
| 1375 |
that the behavior of Pre and Pre'Class will be the same for a particular |
| 1376 |
subprogram, and that the known behavior of the operations can be assumed |
| 1377 |
within the body of that subprogram for Pre'Class. We expect that this change |
| 1378 |
will primarily fix bugs, as it will make Pre'Class and Post'Class work more |
| 1379 |
like expected. In the case where redispatching is desired, an explicit |
| 1380 |
conversion to a class-wide type can be used.]} |
| 1381 |
|
| 1382 |
@end{Inconsistent2012} |
| 1383 |
|
| 1384 |
@begin{Incompatible2012} |
| 1385 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0045-1]} |
| 1386 |
@ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2012}@b<Corrigendum:> |
| 1387 |
Precondition and postcondition aspects cannot be specified on instances of |
| 1388 |
generic subprograms (they should be specified on the generic subprogram |
| 1389 |
instead). This was (unintentionally) allowed by the Ada 2012 standard. |
| 1390 |
These are not be allowed on instances as there is no corresponding way to add |
| 1391 |
preconditions and postconditions to subprograms declared within the instance |
| 1392 |
of a generic package. Therefore, allowing specification on a subprogram |
| 1393 |
instance could present a maintenance problem in the future if the entity |
| 1394 |
needs to be converted to a generic package (a common conversion).]} |
| 1395 |
|
| 1396 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0131-1]} |
| 1397 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Pre'Class is no longer allowed |
| 1398 |
to be specified for an overriding primitive subprogram unless there are |
| 1399 |
also inherited class-wide precondittions. This incompatibility prevents |
| 1400 |
cases where the explicit Pre'Class is counterfeited by an implicit |
| 1401 |
class-wide precondition of True. This rule should catch more bugs than it |
| 1402 |
creates; the programmer should have written Pre rather than Pre'Class in |
| 1403 |
this case (or written Pre'Class on the original subprogram, not |
| 1404 |
an overriding). Note that this incompatibility eliminates what otherwise |
| 1405 |
would be an inconsistency with original Ada 2012, where precondition checks |
| 1406 |
that would have previously been made for a statically bound call would no |
| 1407 |
longer be made. That dynamic change was necessary to eliminate cases where |
| 1408 |
the evaluated class-wide precondition on a dispatching call would have been |
| 1409 |
weaker than the class-wide precondition of a statically bound call. (The |
| 1410 |
original Ada 2012 violated the LSP semantics that class-wide preconditions |
| 1411 |
were intended to model.]} |
| 1412 |
@end{Incompatible2012} |
| 1413 |
|
| 1414 |
|
| 1415 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 1416 |
@LabeledClause{Formal Parameter Modes} |
| 1417 |
|
| 1418 |
@begin{Intro} |
| 1419 |
@Redundant[A @nt{parameter_specification} declares a formal parameter of |
| 1420 |
mode @key[in], @key[in out], or @key[out].] |
| 1421 |
@end{Intro} |
| 1422 |
|
| 1423 |
@begin{StaticSem} |
| 1424 |
@Defn{pass by copy} |
| 1425 |
@Defn{by copy parameter passing} |
| 1426 |
@Defn{copy parameter passing} |
| 1427 |
@Defn{pass by reference} |
| 1428 |
@Defn{by reference parameter passing} |
| 1429 |
@Defn{reference parameter passing} |
| 1430 |
A parameter is passed either @i{by copy} or @i{by reference}. |
| 1431 |
@Redundant[When a parameter is passed by copy, |
| 1432 |
the formal parameter denotes a separate object from the |
| 1433 |
actual parameter, and any information transfer between the two occurs |
| 1434 |
only before and after executing the subprogram. |
| 1435 |
When a parameter is passed by reference, |
| 1436 |
the formal parameter denotes (a view of) the object denoted by the |
| 1437 |
actual parameter; reads and updates of the formal parameter directly |
| 1438 |
reference the actual parameter object.] |
| 1439 |
|
| 1440 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4],ARef=[AI05-0262-1]} |
| 1441 |
@Defn{by-copy type} |
| 1442 |
A type is a @i(by-copy type) if it is an elementary type, |
| 1443 |
or if it is a descendant of a private type whose full type is a |
| 1444 |
by-copy type. A parameter of a by-copy type is passed by |
| 1445 |
copy@Chg{Version=[3],New=[, unless the |
| 1446 |
formal parameter is explicitly aliased],Old=[]}. |
| 1447 |
|
| 1448 |
@leading@keepnext@Defn{by-reference type} |
| 1449 |
A type is a @i(by-reference type) if it |
| 1450 |
is a descendant of one of the following: |
| 1451 |
@begin(itemize) |
| 1452 |
a tagged type; |
| 1453 |
|
| 1454 |
a task or protected type; |
| 1455 |
|
| 1456 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0096-1]} |
| 1457 |
@Chg{Version=[3],New=[an explicitly limited record type],Old=[a |
| 1458 |
nonprivate type with the reserved word @key[limited] in its declaration]}; |
| 1459 |
@begin{Ramification} |
| 1460 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0096-1]} |
| 1461 |
@ChgDeleted{Version=[3],Text=[A limited private type is by-reference |
| 1462 |
only if it falls under one of the other categories.]} |
| 1463 |
@end{Ramification} |
| 1464 |
|
| 1465 |
a composite type with a subcomponent of a by-reference type; |
| 1466 |
|
| 1467 |
a private type |
| 1468 |
whose full type is a by-reference type. |
| 1469 |
@end(itemize) |
| 1470 |
|
| 1471 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4],ARef=[AI05-0188-1]} |
| 1472 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0027-1]} |
| 1473 |
A parameter of a by-reference type is passed by reference@Chg{Version=[3],New=[, as is an explicitly aliased parameter |
| 1474 |
of any type],Old=[]}. |
| 1475 |
@Defn2{Term=[associated object], Sec=(of a value of a by-reference type)} |
| 1476 |
Each value of a by-reference type has an associated object. |
| 1477 |
For a parenthesized expression, @nt{qualified_expression}, |
| 1478 |
or @Chg{Version=[4],New=[view conversion],Old=[@nt{type_conversion}]}, this |
| 1479 |
object is the one associated with the operand.@Chg{Version=[4],New=[ For a value |
| 1480 |
conversion, the associated object is the anonymous result object if such an |
| 1481 |
object is created (see @RefSecNum{Type Conversions}); otherwise it is the |
| 1482 |
associated object of the operand.],Old=[]}@Chg{Version=[3],New=[ For a |
| 1483 |
@nt{conditional_expression}, this object is the one associated with the |
| 1484 |
evaluated @Syni{dependent_}@nt{expression}.],Old=[]} |
| 1485 |
|
| 1486 |
@begin{Ramification} |
| 1487 |
By-reference parameter passing makes sense only if there is an |
| 1488 |
object to reference; hence, we define such an object for each |
| 1489 |
case. |
| 1490 |
|
| 1491 |
Since tagged types are by-reference types, this implies that every value |
| 1492 |
of a tagged type has an associated object. This simplifies things, |
| 1493 |
because we can define the tag to be a property of the object, and not of |
| 1494 |
the value of the object, which makes it clearer that object tags never |
| 1495 |
change. |
| 1496 |
|
| 1497 |
We considered simplifying things even more by making every value (and |
| 1498 |
therefore every expression) have an associated object. After all, |
| 1499 |
there is little semantic difference between a constant object and a |
| 1500 |
value. |
| 1501 |
However, this would cause problems for untagged types. |
| 1502 |
In particular, we would have to do a constraint check on every read of a |
| 1503 |
type conversion (or a renaming thereof) in certain cases. |
| 1504 |
|
| 1505 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 1506 |
We do not want this definition to depend on the view of the type; |
| 1507 |
privateness is essentially ignored for this definition. |
| 1508 |
Otherwise, things would be confusing (does the rule apply at the call |
| 1509 |
site, at the site of the declaration of the subprogram, |
| 1510 |
at the site of the |
| 1511 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]}?), |
| 1512 |
and requiring different calls to use different mechanisms would be an |
| 1513 |
implementation burden. |
| 1514 |
|
| 1515 |
@RefSec{Shared Variable Control} says that a composite type with an |
| 1516 |
atomic or volatile subcomponent is a by-reference type, |
| 1517 |
among other things. |
| 1518 |
|
| 1519 |
@Defn2{Term=[associated object], Sec=(of a value of a limited type)} |
| 1520 |
Every value of a limited by-reference type is the value of |
| 1521 |
one and only one limited object. |
| 1522 |
The @i{associated object} of a value of a limited by-reference type is |
| 1523 |
the object whose value it represents. |
| 1524 |
@Defn2{Term=[same value], Sec=(for a limited type)} |
| 1525 |
Two values of a limited by-reference type are the @i{same} |
| 1526 |
if and only if they represent the value of the same object. |
| 1527 |
|
| 1528 |
We say @lquotes@;by-reference@rquotes@; above because |
| 1529 |
these statements are not always true for limited private types |
| 1530 |
whose underlying type is nonlimited (unfortunately). |
| 1531 |
@end{Ramification} |
| 1532 |
|
| 1533 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0240-1]} |
| 1534 |
@PDefn{unspecified} |
| 1535 |
For @Chg{Version=[3],New=[other ],Old=[]}parameters@Chg{Version=[3],New=[],Old=[ of other types]}, |
| 1536 |
it is unspecified whether the parameter |
| 1537 |
is passed by copy or by reference. |
| 1538 |
@begin{Discussion} |
| 1539 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]} |
| 1540 |
There is no need to incorporate the discussion of AI83-00178, |
| 1541 |
which requires pass-by-copy for certain kinds of actual parameters, |
| 1542 |
while allowing pass-by-reference for others. |
| 1543 |
This is because we explicitly indicate that a function |
| 1544 |
creates an anonymous constant object for its result@Chg{Version=[3],New=[],Old=[, |
| 1545 |
unless the type is a return-by-reference type]} |
| 1546 |
(see @RefSecNum{Return Statements}). |
| 1547 |
We also provide a special dispensation for |
| 1548 |
instances of Unchecked_Conversion to return by reference@Chg{Version=[3],New=[],Old=[, even |
| 1549 |
if the result type is not a return-by-reference type]} |
| 1550 |
(see @RefSecNum{Unchecked Type Conversions}). |
| 1551 |
@end{Discussion} |
| 1552 |
@end{StaticSem} |
| 1553 |
|
| 1554 |
@begin{Bounded} |
| 1555 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0240-1]} |
| 1556 |
@Defn{distinct access paths} |
| 1557 |
@Defn2{Term=[access paths],Sec=(distinct)} |
| 1558 |
@IndexSee{Term=[aliasing],See=(distinct access paths)} |
| 1559 |
@PDefn2{Term=(bounded error),Sec=(cause)} |
| 1560 |
If one @nt<name> denotes a part of a formal parameter, |
| 1561 |
and a second @nt<name> denotes a part of |
| 1562 |
a distinct formal parameter or an object that is not |
| 1563 |
part of a formal parameter, then the two @nt<name>s are |
| 1564 |
considered @i(distinct access paths). |
| 1565 |
If an object is of a type for which the parameter passing |
| 1566 |
mechanism is not specified@Chg{Version=[3],New=[ and is not an |
| 1567 |
explicitly aliased parameter],Old=[]}, then it is a bounded error to |
| 1568 |
assign to the object via one access path, |
| 1569 |
and then read the value of the object via a distinct access path, |
| 1570 |
unless the first access path denotes a part of a formal parameter that |
| 1571 |
no longer exists at the point of the second access |
| 1572 |
@Redundant[(due to leaving the corresponding callable construct).] |
| 1573 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 1574 |
The possible consequences are that Program_Error is raised, |
| 1575 |
or the newly assigned value is read, or some old value of the object is read. |
| 1576 |
@begin{Discussion} |
| 1577 |
For example, if we call @lquotes@;P(X => Global_Variable, Y => Global_Variable)@rquotes@;, |
| 1578 |
then within P, the names @lquotes@;X@rquotes@;, @lquotes@;Y@rquotes@;, and @lquotes@;Global_Variable@rquotes@; |
| 1579 |
are all distinct access paths. |
| 1580 |
If Global_Variable's type is neither pass-by-copy nor pass-by-reference, |
| 1581 |
then it is a bounded error to assign to Global_Variable and |
| 1582 |
then read X or Y, since the language does not specify whether the |
| 1583 |
old or the new value would be read. On the other hand, if |
| 1584 |
Global_Variable's type is pass-by-copy, then the old value would |
| 1585 |
always be read, and there is no error. Similarly, if Global_Variable's |
| 1586 |
type is defined by the language to be pass-by-reference, then the |
| 1587 |
new value would always be read, and again there is no error. |
| 1588 |
@end{Discussion} |
| 1589 |
@begin{Reason} |
| 1590 |
We are saying @i(assign) here, not @i(update), |
| 1591 |
because updating any subcomponent is considered |
| 1592 |
to update the enclosing object. |
| 1593 |
|
| 1594 |
The @lquotes@;still exists@rquotes@; part is so that a read after the subprogram returns |
| 1595 |
is OK. |
| 1596 |
|
| 1597 |
If the parameter is of a by-copy type, |
| 1598 |
then there is no issue here |
| 1599 |
@em the formal is not a view of the actual. |
| 1600 |
If the parameter is of a by-reference type, |
| 1601 |
then the programmer may depend on updates through one access path |
| 1602 |
being visible through some other access path, |
| 1603 |
just as if the parameter were of an access type. |
| 1604 |
@end{Reason} |
| 1605 |
@begin{ImplNote} |
| 1606 |
The implementation can keep a copy in a register of a parameter |
| 1607 |
whose parameter-passing mechanism is not specified. |
| 1608 |
If a different access path is used to update the object (creating |
| 1609 |
a bounded error situation), |
| 1610 |
then the implementation can still use the value of the register, |
| 1611 |
even though the in-memory version of the object has been changed. |
| 1612 |
However, to keep the error properly bounded, |
| 1613 |
if the implementation chooses to read the in-memory version, |
| 1614 |
it has to be consistent -- it cannot then assume that something it has |
| 1615 |
proven about the register is true of the memory location. |
| 1616 |
For example, suppose the formal parameter is L, |
| 1617 |
the value of L(6) is now in a register, and L(6) is used |
| 1618 |
in an @nt{indexed_component} as in @lquotes@;A(L(6)) := 99;@rquotes@;, |
| 1619 |
where A has bounds 1..3. |
| 1620 |
If the implementation can prove that the value for L(6) in the register is in |
| 1621 |
the range 1..3, then it need not perform the constraint check if it |
| 1622 |
uses the register value. |
| 1623 |
However, if the memory value of L(6) has been changed to 4, |
| 1624 |
and the implementation uses that memory value, |
| 1625 |
then it had better not alter memory outside of A. |
| 1626 |
|
| 1627 |
Note that the rule allows the implementation to pass a parameter by |
| 1628 |
reference and then keep just part of it in a register, or, |
| 1629 |
equivalently, to pass part of the parameter by reference and another |
| 1630 |
part by copy. |
| 1631 |
@end{ImplNote} |
| 1632 |
@begin{Reason} |
| 1633 |
@leading@;We do not want to go so far as to say that the mere presence |
| 1634 |
of aliasing is wrong. |
| 1635 |
We wish to be able to write the following sorts of things |
| 1636 |
in standard Ada: |
| 1637 |
@begin{Example} |
| 1638 |
@key[procedure] Move ( Source : @key[in] String; |
| 1639 |
Target : @key[out] String; |
| 1640 |
Drop : @key[in] Truncation := Error; |
| 1641 |
Justify : @key[in] Alignment := Left; |
| 1642 |
Pad : @key[in] Character := Space); |
| 1643 |
--@RI{ Copies elements from Source to Target (safely if they overlap)} |
| 1644 |
@end{Example} |
| 1645 |
|
| 1646 |
This is from the standard string handling package. |
| 1647 |
It would be embarrassing if this couldn't be written in Ada! |
| 1648 |
|
| 1649 |
The @lquotes@;then@rquotes@; before @lquotes@;read@rquotes@; in the rule implies that the implementation |
| 1650 |
can move a read to an earlier place in the code, but not to a later |
| 1651 |
place after a potentially aliased assignment. |
| 1652 |
Thus, if the subprogram reads one of its parameters into a local |
| 1653 |
variable, and then updates another potentially aliased one, |
| 1654 |
the local copy is safe @em it is known to have the old value. |
| 1655 |
For example, the above-mentioned Move subprogram can be implemented |
| 1656 |
by copying Source into a local variable before assigning into Target. |
| 1657 |
|
| 1658 |
@leading@;For an @nt{assignment_statement} assigning one array parameter to another, |
| 1659 |
the implementation has to check which direction to copy |
| 1660 |
at run time, in general, in case the actual parameters are |
| 1661 |
overlapping slices. |
| 1662 |
For example: |
| 1663 |
@begin{Example} |
| 1664 |
@key[procedure] Copy(X : @key[in out] String; Y: String) @key[is] |
| 1665 |
@key[begin] |
| 1666 |
X := Y; |
| 1667 |
@key[end] Copy; |
| 1668 |
@end{Example} |
| 1669 |
|
| 1670 |
It would be wrong for the compiler to assume that X and Y |
| 1671 |
do not overlap (unless, of course, it can prove otherwise). |
| 1672 |
@end{Reason} |
| 1673 |
@end{Bounded} |
| 1674 |
|
| 1675 |
@begin{Notes} |
| 1676 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0056-1]} |
| 1677 |
@ChgAdded{Version=[4],Text=[The mode of a formal parameter describes the |
| 1678 |
direction of information transfer to or from the @nt{subprogram_body} (see |
| 1679 |
@RefSecNum{Subprogram Declarations}).]} |
| 1680 |
|
| 1681 |
A formal parameter of mode @key(in) is a constant |
| 1682 |
view (see @RefSecNum{Objects and Named Numbers}); |
| 1683 |
it cannot be updated within the @nt{subprogram_body}. |
| 1684 |
|
| 1685 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0056-1]} |
| 1686 |
@ChgAdded{Version=[4],Text=[A formal parameter of mode @key(out) |
| 1687 |
might be uninitialized at the start of the @nt{subprogram_body} (see |
| 1688 |
@RefSecNum{Parameter Associations}).]} |
| 1689 |
@end{Notes} |
| 1690 |
|
| 1691 |
@begin{Extend83} |
| 1692 |
@Defn{extensions to Ada 83} |
| 1693 |
The value of an @key(out) parameter may be read. |
| 1694 |
An @key(out) parameter is treated like a declared |
| 1695 |
variable without an explicit initial expression. |
| 1696 |
@end{Extend83} |
| 1697 |
|
| 1698 |
@begin{DiffWord83} |
| 1699 |
Discussion of copy-in for parts of out parameters is now |
| 1700 |
covered in @RefSec{Parameter Associations}. |
| 1701 |
|
| 1702 |
The concept of a by-reference type is new to Ada 95. |
| 1703 |
|
| 1704 |
We now cover in a general way in @RefSecNum{Operations of Discriminated Types} |
| 1705 |
the rule regarding erroneous execution when a discriminant |
| 1706 |
is changed and one of the parameters depends on the discriminant. |
| 1707 |
@end{DiffWord83} |
| 1708 |
|
| 1709 |
@begin{DiffWord2005} |
| 1710 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0096-1]} |
| 1711 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected so that |
| 1712 |
limited derived types are by-reference only if their parent is.]} |
| 1713 |
|
| 1714 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 1715 |
@ChgAdded{Version=[3],Text=[Defined that explicitly aliased parameters |
| 1716 |
(see @RefSecNum{Subprogram Declarations}) are always passed by reference.]} |
| 1717 |
@end{DiffWord2005} |
| 1718 |
|
| 1719 |
@begin{DiffWord2012} |
| 1720 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0027-1]} |
| 1721 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Corrected so that |
| 1722 |
value conversions that are copies are the @ldquote@;associated object@rdquote |
| 1723 |
for parameter passing of by-reference types. This can only happen if the |
| 1724 |
conversion is between unrelated non-limited types, and it is necessary just |
| 1725 |
so the correct object is defined.]} |
| 1726 |
@end{DiffWord2012} |
| 1727 |
|
| 1728 |
|
| 1729 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 1730 |
@LabeledClause{Subprogram Bodies} |
| 1731 |
|
| 1732 |
@begin{Intro} |
| 1733 |
@Redundant[A @nt{subprogram_body} specifies the execution of a |
| 1734 |
subprogram.] |
| 1735 |
@end{Intro} |
| 1736 |
|
| 1737 |
@begin{Syntax} |
| 1738 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00218-03]} |
| 1739 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]} |
| 1740 |
@Syn{lhs=<subprogram_body>,rhs="@Chg{Version=[2],New=< |
| 1741 |
[@Syn2{overriding_indicator}]>,Old=<>} |
| 1742 |
@Syn2{subprogram_specification}@Chg{Version=[3],New=< |
| 1743 |
[@Syn2{aspect_specification}]>,Old=[]} @key{is} |
| 1744 |
@Syn2{declarative_part} |
| 1745 |
@key{begin} |
| 1746 |
@Syn2{handled_sequence_of_statements} |
| 1747 |
@key{end} [@Syn2{designator}];"} |
| 1748 |
|
| 1749 |
@begin{SyntaxText} |
| 1750 |
If a @nt{designator} appears at the end of a @nt{subprogram_body}, |
| 1751 |
it shall repeat the @nt{defining_designator} of the @nt{subprogram_specification}. |
| 1752 |
@end{SyntaxText} |
| 1753 |
@end{Syntax} |
| 1754 |
|
| 1755 |
@begin{Legality} |
| 1756 |
@Redundant[In contrast to other bodies,] |
| 1757 |
a @nt{subprogram_body} need not be the completion of a previous |
| 1758 |
declaration@Redundant[, |
| 1759 |
in which case the body declares the subprogram]. |
| 1760 |
If the body is a completion, it shall be the completion of a |
| 1761 |
@nt{subprogram_declaration} or @nt{generic_subprogram_declaration}. |
| 1762 |
The profile of a @nt{subprogram_body} that completes a declaration |
| 1763 |
shall conform fully to that of the declaration. |
| 1764 |
@Defn2{Term=[full conformance],Sec=(required)} |
| 1765 |
@end{Legality} |
| 1766 |
|
| 1767 |
@begin{StaticSem} |
| 1768 |
A @nt{subprogram_body} is considered a declaration. |
| 1769 |
It can either complete a previous declaration, |
| 1770 |
or itself be the initial declaration of the subprogram. |
| 1771 |
@end{StaticSem} |
| 1772 |
|
| 1773 |
@begin{RunTime} |
| 1774 |
@PDefn2{Term=[elaboration], Sec=(nongeneric subprogram_body)} |
| 1775 |
The elaboration of a nongeneric |
| 1776 |
@nt{subprogram_body} has no other effect than to establish |
| 1777 |
that the subprogram can from then on be called without |
| 1778 |
failing the Elaboration_Check. |
| 1779 |
@begin{Ramification} |
| 1780 |
See @RefSecNum{Generic Bodies} for elaboration of a generic body. |
| 1781 |
Note that protected @ntf{subprogram_bodies} never get elaborated; |
| 1782 |
the elaboration of the containing @nt{protected_body} |
| 1783 |
allows them to be called without failing the Elaboration_Check. |
| 1784 |
@end{Ramification} |
| 1785 |
|
| 1786 |
@PDefn2{Term=[execution], Sec=(subprogram_body)} |
| 1787 |
@Redundant[The execution of a @nt{subprogram_body} is invoked by a |
| 1788 |
subprogram call.] |
| 1789 |
For this execution the @nt{declarative_part} is elaborated, and the |
| 1790 |
@nt{handled_sequence_of_statements} is then executed. |
| 1791 |
@end{RunTime} |
| 1792 |
|
| 1793 |
@begin{Examples} |
| 1794 |
@leading@keepnext@i{Example of procedure body:} |
| 1795 |
@begin{Example} |
| 1796 |
@key[procedure] Push(E : @key[in] Element_Type; S : @key[in] @key[out] Stack) @key[is] |
| 1797 |
@key[begin] |
| 1798 |
@key[if] S.Index = S.Size @key[then] |
| 1799 |
@key[raise] Stack_Overflow; |
| 1800 |
@key[else] |
| 1801 |
S.Index := S.Index + 1; |
| 1802 |
S.Space(S.Index) := E; |
| 1803 |
@key[end] @key[if]; |
| 1804 |
@key[end] Push; |
| 1805 |
@end{Example} |
| 1806 |
|
| 1807 |
@begin{WideAbove} |
| 1808 |
@leading@keepnext@i{Example of a function body:} |
| 1809 |
@end{WideAbove} |
| 1810 |
@begin{Example} |
| 1811 |
@key[function] Dot_Product(Left, Right : Vector) @key[return] Real @key[is] |
| 1812 |
Sum : Real := 0.0; |
| 1813 |
@key[begin] |
| 1814 |
Check(Left'First = Right'First @key[and] Left'Last = Right'Last); |
| 1815 |
@key[for] J @key[in] Left'Range @key[loop] |
| 1816 |
Sum := Sum + Left(J)*Right(J); |
| 1817 |
@key[end] @key[loop]; |
| 1818 |
@key[return] Sum; |
| 1819 |
@key[end] Dot_Product; |
| 1820 |
@end{Example} |
| 1821 |
@end{Examples} |
| 1822 |
|
| 1823 |
@begin{Extend83} |
| 1824 |
@Defn{extensions to Ada 83} |
| 1825 |
A @nt{renaming_declaration} may be used instead of a @nt{subprogram_body}. |
| 1826 |
@end{Extend83} |
| 1827 |
|
| 1828 |
@begin{DiffWord83} |
| 1829 |
The syntax rule for @nt{subprogram_body} now uses the syntactic category |
| 1830 |
@nt{handled_sequence_of_statements}. |
| 1831 |
|
| 1832 |
The @nt{declarative_part} of a @nt{subprogram_body} is now required; |
| 1833 |
that doesn't make any real difference, |
| 1834 |
because a @nt{declarative_part} can be empty. |
| 1835 |
|
| 1836 |
We have incorporated some rules from RM83-6.5 here. |
| 1837 |
|
| 1838 |
RM83 forgot to restrict the definition of elaboration of a |
| 1839 |
@nt{subprogram_body} to nongenerics. |
| 1840 |
@end{DiffWord83} |
| 1841 |
|
| 1842 |
@begin{DiffWord95} |
| 1843 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00218-03]} |
| 1844 |
@ChgAdded{Version=[2],Text=[@nt{Overriding_indicator} is added to |
| 1845 |
@nt{subprogram_body}.]} |
| 1846 |
@end{DiffWord95} |
| 1847 |
|
| 1848 |
@begin{Extend2005} |
| 1849 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 1850 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005}An optional |
| 1851 |
@nt{aspect_specification} can be used in a @nt{subprogram_body}. |
| 1852 |
This is described in @RefSecNum{Aspect Specifications}.]} |
| 1853 |
@end{Extend2005} |
| 1854 |
|
| 1855 |
|
| 1856 |
|
| 1857 |
@LabeledSubClause{Conformance Rules} |
| 1858 |
|
| 1859 |
@begin{Intro} |
| 1860 |
@Defn{conformance} |
| 1861 |
@SeeAlso{Primary=[conformance],Other=(type conformance)} |
| 1862 |
@SeeAlso{Primary=[conformance],Other=(mode conformance)} |
| 1863 |
@SeeAlso{Primary=[conformance],Other=(subtype conformance)} |
| 1864 |
@SeeAlso{Primary=[conformance],Other=(full conformance)} |
| 1865 |
@Redundant[When subprogram profiles are given in more than one place, |
| 1866 |
they are required to conform in one of four ways: type conformance, mode |
| 1867 |
conformance, subtype conformance, or full conformance.] |
| 1868 |
@end{Intro} |
| 1869 |
|
| 1870 |
@begin{StaticSem} |
| 1871 |
@ChgRef{Version=[1],Kind=[Revised],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 1872 |
@leading@Defn{convention} |
| 1873 |
@Defn{calling convention} |
| 1874 |
@Redundant[As explained in @RefSec{Interfacing Aspects}, |
| 1875 |
a @i{convention} can be specified for an entity.] |
| 1876 |
@Chg{New=[Unless this International Standard states otherwise, the default |
| 1877 |
convention of an entity is Ada.],Old=[]} |
| 1878 |
@Redundant[For a callable entity or access-to-subprogram type, |
| 1879 |
the convention is called the @i{calling convention}.] |
| 1880 |
The following conventions are defined by the language: |
| 1881 |
@begin{Itemize} |
| 1882 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 1883 |
@Defn{Ada calling convention} |
| 1884 |
@Defn2{Term=[calling convention], Sec=(Ada)} |
| 1885 |
The default calling convention for any subprogram not listed below is |
| 1886 |
@i{Ada}. |
| 1887 |
@Redundant[@Chg{Version=[3],New=[The],Old=[A @nt{pragma}]} |
| 1888 |
Convention@Chg{Version=[3],New=[ aspect],Old=[, Import, or Export]} |
| 1889 |
may be @Chg{Version=[3],New=[specified],Old=[used]} to override |
| 1890 |
the default calling convention (see @RefSecNum{Interfacing Aspects})]. |
| 1891 |
@begin{Ramification} |
| 1892 |
See also the rule about renamings-as-body |
| 1893 |
in @RefSecNum{Subprogram Renaming Declarations}. |
| 1894 |
@end{Ramification} |
| 1895 |
|
| 1896 |
@leading@Defn{Intrinsic calling convention} |
| 1897 |
@Defn2{Term=[calling convention], Sec=(Intrinsic)} |
| 1898 |
The @i{Intrinsic} calling convention represents |
| 1899 |
subprograms that are @lquotes@;built in@rquotes@; to the compiler. |
| 1900 |
The default calling convention is Intrinsic for the following: |
| 1901 |
@begin{InnerItemize} |
| 1902 |
an enumeration literal; |
| 1903 |
|
| 1904 |
a "/=" operator declared implicitly due to |
| 1905 |
the declaration of "=" (see @RefSecNum{Overloading of Operators}); |
| 1906 |
|
| 1907 |
any other implicitly declared subprogram unless it is |
| 1908 |
a dispatching operation of a tagged type; |
| 1909 |
|
| 1910 |
an inherited subprogram of a generic formal tagged type |
| 1911 |
with unknown discriminants; |
| 1912 |
@begin{Reason} |
| 1913 |
@Comment{8652/0011 suggests that the reason for this rule be documented in |
| 1914 |
the AARM.} |
| 1915 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1916 |
@Chg{New=[Consider:],Old=[]} |
| 1917 |
@begin{Example} |
| 1918 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1919 |
@Chg{New=[@key[package] P @key[is] |
| 1920 |
@key[type] Root @key[is tagged null record]; |
| 1921 |
@key[procedure] Proc(X: Root); |
| 1922 |
@key[end] P;],Old=[]} |
| 1923 |
|
| 1924 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1925 |
@Chg{New=[@key[generic] |
| 1926 |
@key[type] Formal(<>) @key[is new] Root @key[with private]; |
| 1927 |
@key[package] G @key[is] |
| 1928 |
... |
| 1929 |
@key[end] G;],Old=[]} |
| 1930 |
|
| 1931 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1932 |
@ChgAdded{Version=[1],Text=[@key[package body] G @key[is] |
| 1933 |
... |
| 1934 |
X: Formal := ...; |
| 1935 |
... |
| 1936 |
Proc(X); -- @RI[This is a dispatching call in Instance, because] |
| 1937 |
-- @RI[the actual type for Formal is class-wide.] |
| 1938 |
... |
| 1939 |
-- @RI[Proc'Access would be illegal here, because it is of] |
| 1940 |
-- @RI[convention Intrinsic, by the above rule.] |
| 1941 |
@key[end] G;]} |
| 1942 |
|
| 1943 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1944 |
@ChgAdded{Version=[1],Text=[@key[type] Actual @key[is new] Root @key[with] ...; |
| 1945 |
@key[procedure] Proc(X: Actual); |
| 1946 |
@key[package] Instance @key[is new] G(Formal => Actual'Class); |
| 1947 |
-- @RI[It is legal to pass in a class-wide actual, because Formal] |
| 1948 |
-- @RI[has unknown discriminants.]]} |
| 1949 |
@end{Example} |
| 1950 |
|
| 1951 |
@ChgRef{Version=[1],Kind=[Added]} |
| 1952 |
@Chg{New=[Within Instance, all calls to Proc will be dispatching calls, so Proc doesn't |
| 1953 |
really exist in machine code, so we wish to avoid taking 'Access of it. |
| 1954 |
This rule applies to those cases where the actual type might be class-wide, |
| 1955 |
and makes these Intrinsic, thus forbidding 'Access.],Old=[]} |
| 1956 |
@end{Reason} |
| 1957 |
|
| 1958 |
|
| 1959 |
an attribute that is a subprogram; |
| 1960 |
|
| 1961 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00252-01]} |
| 1962 |
a subprogram declared immediately |
| 1963 |
within a @nt{protected_body}@Chg{Version=[2],New=[;],Old=[.]} |
| 1964 |
|
| 1965 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00252-01],ARef=[AI95-00407-01]} |
| 1966 |
@ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0107-1]} |
| 1967 |
@ChgAdded{Version=[2],Text=[any prefixed view of a subprogram (see |
| 1968 |
@RefSecNum{Selected Components})@Chg{Version=[4],New=[ without |
| 1969 |
synchronization kind (see @RefSecNum{Intertask Communication}) By_Entry or |
| 1970 |
By_Protected_Procedure],Old=[]}.]} |
| 1971 |
@begin{Reason} |
| 1972 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 1973 |
@ChgAdded{Version=[2],Text=[The profile of a prefixed view is |
| 1974 |
different than the @lquotes@;real@rquotes profile of the subprogram |
| 1975 |
(it doesn't have the first parameter), so we don't want to be able |
| 1976 |
to take 'Access of it, as that would require generating a wrapper of |
| 1977 |
some sort.]} |
| 1978 |
|
| 1979 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0107-1]} |
| 1980 |
@ChgAdded{Version=[4],Text=[We except prefixed views that have |
| 1981 |
synchronization kind By_Protected_Procedure so that they can be used |
| 1982 |
with an access-to-protected-procedure type. These don't require special |
| 1983 |
wrappers (this is the normal form for a protected subprogram call). The |
| 1984 |
By_Entry part is just for consistency (there is no access-to-entry type |
| 1985 |
in Ada).]} |
| 1986 |
@end{Reason} |
| 1987 |
|
| 1988 |
@end{InnerItemize} |
| 1989 |
|
| 1990 |
@NoPrefix@Redundant[The Access attribute is not allowed |
| 1991 |
for Intrinsic subprograms.] |
| 1992 |
@begin{Ramification} |
| 1993 |
The Intrinsic calling convention really represents any number of |
| 1994 |
calling conventions at the machine code level; |
| 1995 |
the compiler might have a different instruction sequence for |
| 1996 |
each intrinsic. |
| 1997 |
That's why the Access attribute is disallowed. |
| 1998 |
We do not wish to require the implementation to generate |
| 1999 |
an out of line body for an intrinsic. |
| 2000 |
|
| 2001 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2002 |
Whenever we wish to disallow the Access attribute in order to ease |
| 2003 |
implementation, we make the subprogram Intrinsic. |
| 2004 |
Several language-defined subprograms have |
| 2005 |
@lquotes@;@Chg{Version=[3],New=[@key[with]],Old=[@key[pragma]]} |
| 2006 |
Convention@Chg{Version=[3],New=[ => ],Old=[(]}Intrinsic@Chg{Version=[3],New=[],Old=[, ...)]};@rquotes@;. |
| 2007 |
An implementation might actually implement this |
| 2008 |
as @lquotes@;@Chg{Version=[3],New=[@key[with]],Old=[@key[pragma]]} |
| 2009 |
Import@Chg{Version=[3],New=[ => True, Convention |
| 2010 |
=> ],Old=[(]}Intrinsic@Chg{Version=[3],New=[],Old=[, ...)]};@rquotes@;, |
| 2011 |
if there is really no body, and the implementation of the subprogram |
| 2012 |
is built into the code generator. |
| 2013 |
|
| 2014 |
Subprograms declared in @ntf{protected_bodies} will generally have a |
| 2015 |
special calling |
| 2016 |
convention so as to pass along the identification of the |
| 2017 |
current instance of the protected type. |
| 2018 |
The convention is not @i(protected) since such local subprograms |
| 2019 |
need not contain any @lquotes@;locking@rquotes@; logic since they are |
| 2020 |
not callable via @lquotes@;external@rquotes@; calls; |
| 2021 |
this rule prevents an access value designating such a subprogram |
| 2022 |
from being passed outside the protected unit. |
| 2023 |
|
| 2024 |
The @lquotes@;implicitly declared subprogram@rquotes@; above refers to |
| 2025 |
predefined operators (other than the "=" of a tagged type) and |
| 2026 |
the inherited subprograms of |
| 2027 |
untagged types. |
| 2028 |
@end{Ramification} |
| 2029 |
|
| 2030 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0107-1],ARef=[AI12-0159-1]} |
| 2031 |
@Defn{protected calling convention} |
| 2032 |
@Defn2{Term=[calling convention], Sec=(protected)} |
| 2033 |
The default calling convention is @i{protected} |
| 2034 |
for a protected subprogram,@Chg{Version=[4],New=[ for a |
| 2035 |
prefixed view of a subprogram with a synchronization kind of |
| 2036 |
By_Protected_Procedure,],Old=[]} |
| 2037 |
and for an access-to-subprogram type with |
| 2038 |
the reserved word @key(protected) in its definition. |
| 2039 |
|
| 2040 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0107-1],ARef=[AI12-0159-1]} |
| 2041 |
@Defn{entry calling convention} |
| 2042 |
@Defn2{Term=[calling convention], Sec=(entry)} |
| 2043 |
The default calling convention is @i{entry} for an |
| 2044 |
entry@Chg{Version=[4],New=[ and for a prefixed view |
| 2045 |
of a subprogram with a synchronization kind of By_Entry],Old=[]}. |
| 2046 |
|
| 2047 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00254-01],ARef=[AI95-00409-01]} |
| 2048 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0264-1]} |
| 2049 |
@ChgAdded{Version=[2],Text=[The calling convention for an |
| 2050 |
anonymous access-to-subprogram parameter |
| 2051 |
or anonymous access-to-subprogram result is @i<protected> if the reserved |
| 2052 |
word @key{protected} appears in its definition@Chg{Version=[3],New=[;],Old=[ and]} |
| 2053 |
otherwise@Chg{Version=[3],New=[, it],Old=[]} is the convention |
| 2054 |
of the subprogram that contains the parameter.]} |
| 2055 |
@begin{Ramification} |
| 2056 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2057 |
@ChgAdded{Version=[2],Text=[The calling convention for other |
| 2058 |
anonymous access-to-subprogram types is Ada.]} |
| 2059 |
@end{Ramification} |
| 2060 |
|
| 2061 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 2062 |
@Chg{Version=[1],New=[@Redundant[If not specified above as Intrinsic, the calling convention for any |
| 2063 |
inherited or overriding dispatching operation of a tagged type is that of the |
| 2064 |
corresponding subprogram of the parent type.] The default calling convention |
| 2065 |
for a new dispatching operation of a tagged type is the convention of the type.], |
| 2066 |
Old=[]} |
| 2067 |
@begin{Reason} |
| 2068 |
@ChgRef{Version=[1],Kind=[Added]} |
| 2069 |
@ChgAdded{Version=[1],Text=[The first rule is officially stated in |
| 2070 |
@RefSecNum(Dispatching Operations of Tagged Types). The second is intended |
| 2071 |
to make interfacing to foreign OOP languages easier, by making the default |
| 2072 |
be that the type and operations all have the same convention.]} |
| 2073 |
@end{Reason} |
| 2074 |
@end{Itemize} |
| 2075 |
|
| 2076 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2077 |
Of these four conventions, only Ada and Intrinsic are |
| 2078 |
allowed as a @SynI{convention_}@nt{identifier} |
| 2079 |
in @Chg{Version=[3],New=[the specification of a],Old=[a @nt{pragma}]} |
| 2080 |
Convention@Chg{Version=[3],New=[ aspect],Old=[, Import, or Export]}. |
| 2081 |
@begin{Discussion} |
| 2082 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2083 |
The names of the @i{protected} and @i{entry} calling conventions |
| 2084 |
cannot be used in the @Chg{Version=[3],New=[specification of Convention], |
| 2085 |
Old=[interfacing pragmas]}. |
| 2086 |
Note that @key[protected] and @key[entry] are reserved words. |
| 2087 |
@end{Discussion} |
| 2088 |
|
| 2089 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00409-01]} |
| 2090 |
@Defn{type conformance} |
| 2091 |
@Defn2{Term=[profile],Sec=(type conformant)} |
| 2092 |
Two profiles |
| 2093 |
are @i{type conformant} if they have the same number of parameters, |
| 2094 |
and both have a result if either does, and corresponding |
| 2095 |
parameter and result types are the same, |
| 2096 |
or, for access parameters@Chg{Version=[2],New=[ or access results],Old=[]}, |
| 2097 |
corresponding designated types are the same@Chg{Version=[2],New=[, or |
| 2098 |
corresponding designated profiles are type conformant],Old=[]}. |
| 2099 |
@IndexSee{Term=[type profile],See=(profile, type conformant)} |
| 2100 |
@begin{Discussion} |
| 2101 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00409-01]} |
| 2102 |
For @Chg{Version=[2],New=[anonymous access-to-object],Old=[access]} |
| 2103 |
parameters, the designated types have to be the same for type |
| 2104 |
conformance, not the access types, |
| 2105 |
since in general each access parameter has its own anonymous access |
| 2106 |
type, created when the subprogram is called. |
| 2107 |
Of course, corresponding parameters have to be either both access |
| 2108 |
parameters or both not access parameters. |
| 2109 |
|
| 2110 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]} |
| 2111 |
@ChgAdded{Version=[2],Text=[Similarly, for anonymous access-to-subprogram |
| 2112 |
parameters, the designated profiles of the types, not the types themselves, |
| 2113 |
have to be conformant.]} |
| 2114 |
@end{Discussion} |
| 2115 |
|
| 2116 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00409-01]} |
| 2117 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0142-4]} |
| 2118 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{Dummy for conditional leading.} |
| 2119 |
@Defn{mode conformance} |
| 2120 |
@Defn2{Term=[profile],Sec=(mode conformant)} |
| 2121 |
Two profiles are @i{mode conformant} if@Chg{Version=[3],New=[:],Old=[ they are |
| 2122 |
type-conformant, and |
| 2123 |
corresponding parameters have identical |
| 2124 |
modes, and, for access |
| 2125 |
parameters@Chg{Version=[2],New=[ or access result types],Old=[]}, the |
| 2126 |
designated subtypes statically match@Chg{Version=[2],New=[, or the |
| 2127 |
designated profiles are subtype conformant.],Old=[]} |
| 2128 |
@PDefn2{Term=[statically matching],Sec=(required)}]} |
| 2129 |
|
| 2130 |
@begin{Itemize} |
| 2131 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0262-1]} |
| 2132 |
@ChgAdded{Version=[3],Text=[they are type conformant; and]} |
| 2133 |
|
| 2134 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4]} |
| 2135 |
@ChgAdded{Version=[3],Text=[corresponding parameters have identical modes and |
| 2136 |
both or neither are explicitly aliased parameters; and]} |
| 2137 |
|
| 2138 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0207-1]} |
| 2139 |
@ChgAdded{Version=[3],Text=[for corresponding access parameters and any access |
| 2140 |
result type, the designated subtypes statically match and either both or neither |
| 2141 |
are access-to-constant, or the designated profiles are subtype conformant. |
| 2142 |
@PDefn2{Term=[statically matching],Sec=(required)}]} |
| 2143 |
@end{Itemize} |
| 2144 |
|
| 2145 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0239-1]} |
| 2146 |
@Defn{subtype conformance} |
| 2147 |
@Defn2{Term=[profile],Sec=(subtype conformant)} |
| 2148 |
Two profiles are @i{subtype conformant} if they are |
| 2149 |
@Chg{Version=[3],New=[mode conformant],Old=[mode-conformant]}, |
| 2150 |
corresponding subtypes of the profile statically match, |
| 2151 |
and the associated calling conventions are the same. |
| 2152 |
The profile of a generic formal subprogram is not |
| 2153 |
@Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]} |
| 2154 |
with any other profile. |
| 2155 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 2156 |
|
| 2157 |
@begin{Ramification} |
| 2158 |
@PDefn{generic contract issue} |
| 2159 |
@end{Ramification} |
| 2160 |
|
| 2161 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0134-1],ARef=[AI05-0262-1]} |
| 2162 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{Dummy for conditional leading.} |
| 2163 |
@Defn2{Term=[full conformance], Sec=(for profiles)} |
| 2164 |
@Defn2{Term=[profile],Sec=(fully conformant)} |
| 2165 |
Two profiles are @i{fully conformant} if they |
| 2166 |
are @Chg{Version=[3],New=[subtype conformant],Old=[subtype-conformant]}, |
| 2167 |
@Chg{Version=[3],New=[if they have |
| 2168 |
access-to-subprogram results whose designated profiles are fully |
| 2169 |
conformant, ],Old=[]}and @Chg{Version=[3],New=[for ],Old=[]} |
| 2170 |
corresponding parameters@Chg{Version=[3],New=[:], |
| 2171 |
Old=[ have the same names and have @nt<default_expression>s |
| 2172 |
that are fully conformant with one another.]} |
| 2173 |
@begin{Itemize} |
| 2174 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0262-1]} |
| 2175 |
@ChgAdded{Version=[3],Text=[they have the same names; and]} |
| 2176 |
|
| 2177 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0046-1]} |
| 2178 |
@ChgAdded{Version=[3],Text=[both or neither have @nt{null_exclusion}s; and]} |
| 2179 |
|
| 2180 |
@ChgRef{Version=[3],Kind=[Added]} |
| 2181 |
@ChgAdded{Version=[3],Text=[neither have @nt{default_expression}s, or they both |
| 2182 |
have @nt{default_expression}s that are fully conformant with one another; and]} |
| 2183 |
|
| 2184 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0134-1]} |
| 2185 |
@ChgAdded{Version=[3],Text=[for access-to-subprogram parameters, the designated |
| 2186 |
profiles are fully conformant.]} |
| 2187 |
@end{Itemize} |
| 2188 |
@begin{Ramification} |
| 2189 |
Full conformance requires subtype conformance, |
| 2190 |
which requires the same calling conventions. |
| 2191 |
However, the calling convention of the declaration and body of a |
| 2192 |
subprogram or entry are always the same by definition. |
| 2193 |
@end{Ramification} |
| 2194 |
@begin{Reason} |
| 2195 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0046-1]} |
| 2196 |
@ChgAdded{Version=[3],Text=[The part about @nt{null_exclusion}s is |
| 2197 |
necessary to prevent controlling parameters from having different |
| 2198 |
exclusions, as such a parameter is defined to exclude |
| 2199 |
null whether or not an exclusion is given.]} |
| 2200 |
|
| 2201 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0134-1]} |
| 2202 |
@ChgAdded{Version=[3],Text=[The parts about access-to-subprogram parameters |
| 2203 |
and results is necessary to prevent such types from having different |
| 2204 |
@nt{default_expression}s in the specification and body of a subprogram. |
| 2205 |
If that was allowed, it would be undefined which @nt{default_expression} |
| 2206 |
was used in a call of an access-to-subprogram parameter.]} |
| 2207 |
@end{Reason} |
| 2208 |
|
| 2209 |
@leading@Defn2{Term=[full conformance], Sec=(for expressions)} |
| 2210 |
Two expressions are @i(fully conformant) if, |
| 2211 |
@Redundant[after replacing each use of an operator with the equivalent |
| 2212 |
@nt{function_call}:] |
| 2213 |
@begin{Itemize} |
| 2214 |
each constituent construct of one corresponds to an instance of the |
| 2215 |
same syntactic category in the other, |
| 2216 |
except that an expanded name may correspond |
| 2217 |
to a @nt{direct_name} |
| 2218 |
(or @nt{character_literal}) |
| 2219 |
or to a different expanded name in the other; and |
| 2220 |
|
| 2221 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0050-1]} |
| 2222 |
@ChgAdded{Version=[4],Text=[corresponding @nt{defining_identifier}s occurring |
| 2223 |
within the two expressions are the same; and]} |
| 2224 |
|
| 2225 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0050-1]} |
| 2226 |
each @nt{direct_name}, @nt{character_literal}, and @nt{selector_name} |
| 2227 |
that is not part of the @nt{prefix} of an expanded name in one |
| 2228 |
denotes the same declaration as the corresponding |
| 2229 |
@nt{direct_name}, @nt{character_literal}, |
| 2230 |
or @nt{selector_name} in the other@Chg{Version=[4],New=[, or they denote |
| 2231 |
corresponding declarations occurring within the two expressions],Old=[]}; and |
| 2232 |
@begin{Ramification} |
| 2233 |
Note that it doesn't say @lquotes@;respectively@rquotes@; |
| 2234 |
because a @nt{direct_name} can correspond to a @nt{selector_name}, |
| 2235 |
and vice-versa, by the previous bullet. |
| 2236 |
This rule allows the @nt{prefix} of an expanded name to be removed, |
| 2237 |
or replaced with a different @nt{prefix} that denotes a renaming of the |
| 2238 |
same entity. |
| 2239 |
However, it does not allow a @nt{direct_name} or @nt{selector_name} to |
| 2240 |
be replaced with one denoting a distinct renaming |
| 2241 |
(except for @nt{direct_name}s and @nt{selector_name}s in @nt{prefix}es |
| 2242 |
of expanded names). |
| 2243 |
Note that calls using operator notation |
| 2244 |
are equivalent to calls using prefix notation. |
| 2245 |
|
| 2246 |
@leading@keepnext@;Given the following declarations: |
| 2247 |
@begin{Example} |
| 2248 |
@key[package] A @key[is] |
| 2249 |
@key[function] F(X : Integer := 1) @key[return] Boolean; |
| 2250 |
@key[end] A; |
| 2251 |
|
| 2252 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0005-1]} |
| 2253 |
@key[with] A; |
| 2254 |
@key[package] B @key[is] |
| 2255 |
@key[package] A_View @key[renames] A; |
| 2256 |
@key[function] F_View(X : Integer := 9999) @key[return] Boolean @key[renames] @Chg{Version=[3],New=[A.F],Old=[F]}; |
| 2257 |
@key[end] B; |
| 2258 |
|
| 2259 |
@key[with] A, B; @key[use] A, B; |
| 2260 |
@key[procedure] Main @key[is] ... |
| 2261 |
@end{Example} |
| 2262 |
|
| 2263 |
Within Main, the expressions @lquotes@;F@rquotes@;, @lquotes@;A.F@rquotes@;, @lquotes@;B.A_View.F@rquotes@;, |
| 2264 |
and @lquotes@;A_View.F@rquotes@; are all fully conformant with one another. |
| 2265 |
However, @lquotes@;F@rquotes@; and @lquotes@;F_View@rquotes@; are not fully conformant. |
| 2266 |
If they were, it would be bad news, since the two denoted views have |
| 2267 |
different @nt{default_expression}s. |
| 2268 |
@end{Ramification} |
| 2269 |
@begin{Discussion} |
| 2270 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0050-1]} |
| 2271 |
@ChgAdded{Version=[4],Text=[We talk about @nt{defining_identifier}s and |
| 2272 |
"corresponding declarations" because of the possibility of |
| 2273 |
@nt{iterator_specification}s occurring within the expressions; each |
| 2274 |
@nt{iterator_specification} is a separate declaration, which we need to |
| 2275 |
allow, but we do want to require that the @nt{defining_identifier}s are |
| 2276 |
the same.]} |
| 2277 |
@end{Discussion} |
| 2278 |
|
| 2279 |
@ChgRef{Version=[1],Kind=[Added],Ref=[8652/0018],ARef=[AI95-00175-01]} |
| 2280 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0092-1]} |
| 2281 |
@ChgAdded{Version=[1],Text=[each @nt{attribute_designator} in one |
| 2282 |
@Chg{Version=[3],New=[is],Old=[must be]} the same as the |
| 2283 |
corresponding @nt{attribute_designator} in the other; and]} |
| 2284 |
|
| 2285 |
each @nt{primary} that is a literal in one |
| 2286 |
has the same value as the corresponding literal in the other. |
| 2287 |
@begin{Ramification} |
| 2288 |
The literals may be written differently. |
| 2289 |
@end{Ramification} |
| 2290 |
@end{Itemize} |
| 2291 |
@begin{Ramification} |
| 2292 |
Note that the above definition makes full conformance a transitive |
| 2293 |
relation. |
| 2294 |
@end{Ramification} |
| 2295 |
|
| 2296 |
@Defn2{Term=[full conformance], Sec=(for @nt{known_discriminant_part}s)} |
| 2297 |
Two @nt{known_discriminant_part}s are @i(fully conformant) if they have |
| 2298 |
the same number of discriminants, and |
| 2299 |
discriminants in the same positions |
| 2300 |
have the same names, statically matching subtypes, |
| 2301 |
and @nt{default_expression}s that are fully conformant with |
| 2302 |
one another. |
| 2303 |
@PDefn2{Term=[statically matching],Sec=(required)} |
| 2304 |
|
| 2305 |
@Defn2{Term=[full conformance], Sec=(for @nt{discrete_subtype_definition}s)} |
| 2306 |
Two @nt<discrete_subtype_definition>s are @i(fully conformant) if they |
| 2307 |
are both @nt<subtype_indication>s or are both @nt<range>s, |
| 2308 |
the @nt<subtype_mark>s (if any) denote the same subtype, and |
| 2309 |
the corresponding @nt<simple_expression>s of the @nt<range>s (if any) |
| 2310 |
fully conform. |
| 2311 |
@begin{Ramification} |
| 2312 |
In the @nt{subtype_indication} case, any ranges have to @i{be} |
| 2313 |
corresponding; that is, two @nt{subtype_indication}s cannot conform |
| 2314 |
unless both or neither has a @nt{range}. |
| 2315 |
@end{Ramification} |
| 2316 |
@begin{Discussion} |
| 2317 |
This definition is used in @RefSec(Entries and Accept Statements) |
| 2318 |
for the conformance required between the @nt<discrete_subtype_definition>s |
| 2319 |
of an @nt<entry_declaration> for a family of entries and the |
| 2320 |
corresponding @nt<entry_index_specification> of the @nt<entry_body>. |
| 2321 |
@end{Discussion} |
| 2322 |
|
| 2323 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01],ARef=[AI95-00397-01]} |
| 2324 |
@ChgAdded{Version=[2],Text=[@Defn{prefixed view profile} |
| 2325 |
The @i<prefixed view profile> of a subprogram is the profile obtained by |
| 2326 |
omitting the first parameter of that subprogram. There is no prefixed view |
| 2327 |
profile for a parameterless subprogram. For the purposes of defining subtype |
| 2328 |
and mode conformance, the convention of a prefixed view profile is considered |
| 2329 |
to match that of either an entry or a protected operation.]} |
| 2330 |
|
| 2331 |
@begin{Discussion} |
| 2332 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2333 |
@ChgAdded{Version=[2],Text=[This definition is used to define how |
| 2334 |
primitive subprograms of interfaces match operations in task and |
| 2335 |
protected type definitions (see @RefSecNum{Task Units and Task Objects} and |
| 2336 |
@RefSecNum{Protected Units and Protected Objects}).]} |
| 2337 |
@end{Discussion} |
| 2338 |
@begin{Reason} |
| 2339 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2340 |
@ChgAdded{Version=[2],Text=[The weird rule about conventions is pretty much |
| 2341 |
required for synchronized interfaces to make any sense. There will be |
| 2342 |
wrappers all over the place for interfaces anyway. Of course, this doesn't |
| 2343 |
imply that entries have the same convention as protected operations.]} |
| 2344 |
@end{Reason} |
| 2345 |
@end{StaticSem} |
| 2346 |
|
| 2347 |
@begin{ImplPerm} |
| 2348 |
|
| 2349 |
An implementation may declare an operator declared in a language-defined |
| 2350 |
library unit to be intrinsic. |
| 2351 |
|
| 2352 |
@end{ImplPerm} |
| 2353 |
|
| 2354 |
@begin{Extend83} |
| 2355 |
@Defn{extensions to Ada 83} |
| 2356 |
The rules for full conformance are relaxed @em they are now based on |
| 2357 |
the structure of constructs, rather than the sequence of lexical |
| 2358 |
elements. This implies, for example, that "(X, Y: T)" |
| 2359 |
conforms fully with "(X: T; Y: T)", |
| 2360 |
and "(X: T)" conforms fully with "(X: @key[in] T)". |
| 2361 |
@end{Extend83} |
| 2362 |
|
| 2363 |
@begin{DiffWord95} |
| 2364 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0011],ARef=[AI95-00117-01]} |
| 2365 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Clarified that the default |
| 2366 |
convention is Ada. Also clarified that the convention of a primitive |
| 2367 |
operation of a tagged type is the same as that of the type.]} |
| 2368 |
|
| 2369 |
@ChgRef{Version=[2],Kind=[AddedNormal],Ref=[8652/0018],ARef=[AI95-00175-01]} |
| 2370 |
@ChgAdded{Version=[2],Text=[@b<Corrigendum:> Added wording to ensure that two |
| 2371 |
attributes conform only if they have the same @nt{attribute_designator}.]} |
| 2372 |
|
| 2373 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00252-01],ARef=[AI95-00254-01],ARef=[AI95-00407-01]} |
| 2374 |
@ChgAdded{Version=[2],Text=[Defined the calling convention for anonymous |
| 2375 |
access-to-subprogram types and for prefixed views of subprograms (see |
| 2376 |
@RefSecNum{Selected Components}).]} |
| 2377 |
|
| 2378 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 2379 |
@ChgAdded{Version=[2],Text=[Defined the conformance of access result types |
| 2380 |
(see @RefSecNum{Subprogram Declarations}).]} |
| 2381 |
|
| 2382 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01],ARef=[AI95-00397-01]} |
| 2383 |
@ChgAdded{Version=[2],Text=[Defined the prefixed view profile of subprograms |
| 2384 |
for later use.]} |
| 2385 |
|
| 2386 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00409-01]} |
| 2387 |
@ChgAdded{Version=[2],Text=[Defined the conformance of anonymous |
| 2388 |
access-to-subprogram parameters.]} |
| 2389 |
@end{DiffWord95} |
| 2390 |
|
| 2391 |
@begin{Incompatible2005} |
| 2392 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0046-1]} |
| 2393 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:> Now require |
| 2394 |
@nt{null_exclusion}s to match for full conformance. While this is |
| 2395 |
technically incompatible with Ada 2005 as defined by Amendment 1, |
| 2396 |
it is a new Ada 2005 feature and it is unlikely that users have |
| 2397 |
been intentionally taking advantage of the ability to write mismatching |
| 2398 |
exclusions. In any case, it is easy to fix: add a @nt{null_exclusion} |
| 2399 |
where needed for conformance.]} |
| 2400 |
|
| 2401 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0134-1]} |
| 2402 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Now require |
| 2403 |
full conformance of anonymous access-to-subprogram parameters and results |
| 2404 |
for full conformance. This is necessary so that there is no confusion about |
| 2405 |
the default expression that is used for a call. While this is technically |
| 2406 |
incompatible with Ada 2005 as defined by Amendment 1, it is a new Ada 2005 |
| 2407 |
feature and it is unlikely that users have been intentionally taking advantage |
| 2408 |
and writing different default expressions. In any case, it is |
| 2409 |
easy to fix: change any default expressions that don't conform so that they |
| 2410 |
do conform.]} |
| 2411 |
|
| 2412 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0207-1]} |
| 2413 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Now include |
| 2414 |
the presence or absence of @key[constant] in access parameters to be |
| 2415 |
considered when checking mode conformance. This is necessary to prevent |
| 2416 |
modification of constants. While this is technically incompatible with |
| 2417 |
Ada 2005 as defined by Amendment 1, it is a new Ada 2005 feature and it |
| 2418 |
is unlikely that users have been intentionally taking advantage and writing |
| 2419 |
mismatching access types.]} |
| 2420 |
@end{Incompatible2005} |
| 2421 |
|
| 2422 |
@begin{Diffword2005} |
| 2423 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 2424 |
@ChgAdded{Version=[3],Text=[Explicitly aliased parameters are included |
| 2425 |
as part of mode conformance (since it affects the parameter passing |
| 2426 |
mechanism).]} |
| 2427 |
@end{Diffword2005} |
| 2428 |
|
| 2429 |
@begin{Extend2012} |
| 2430 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0107-1],ARef=[AI05-0159-1]} |
| 2431 |
@ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012}@b<Corrigendum:> |
| 2432 |
We now define that a prefixed view of a subprogram with synchronization |
| 2433 |
kind By_Protected_Procedure can be used as the prefix of 'Access for an |
| 2434 |
access-to-protected type. We consider this a correction as it certainly |
| 2435 |
appears that it ought to work, but in original Ada 2012 it would have had |
| 2436 |
a convention mismatch.]} |
| 2437 |
@end{Extend2012} |
| 2438 |
|
| 2439 |
@begin{Diffword2012} |
| 2440 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 2441 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> We now define how two |
| 2442 |
expressions containing quantified expressions can fully conform. This |
| 2443 |
isn't incompatible, as the original Ada 2012 never allowed such expressions |
| 2444 |
to conform (the declarations in each formally being different). Neither is |
| 2445 |
it an extension as one would expect these to conform.]} |
| 2446 |
@end{Diffword2012} |
| 2447 |
|
| 2448 |
|
| 2449 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 2450 |
@LabeledSubClause{Inline Expansion of Subprograms} |
| 2451 |
|
| 2452 |
@begin{Intro} |
| 2453 |
@Redundant[Subprograms may be expanded in line at the call site.] |
| 2454 |
@end{Intro} |
| 2455 |
|
| 2456 |
@begin{NotIso} |
| 2457 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2 |
| 2458 |
through 4 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message |
| 2459 |
should be deleted if the paragraphs are ever renumbered.} |
| 2460 |
@end{NotIso} |
| 2461 |
|
| 2462 |
@begin{Syntax} |
| 2463 |
@begin{SyntaxText} |
| 2464 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 2465 |
@ChgDeleted{Version=[3],Type=[Leading],KeepNext=[T],Text=[@PDefn2{Term=[program unit pragma], Sec=(Inline)} |
| 2466 |
@PDefn2{Term=[pragma, program unit], Sec=(Inline)} |
| 2467 |
The form of a @nt{pragma} Inline, |
| 2468 |
which is a program unit pragma (see @RefSecNum{Pragmas and Program Units}), |
| 2469 |
is as follows:]} |
| 2470 |
@end{SyntaxText} |
| 2471 |
|
| 2472 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 2473 |
@DeletedPragmaSyn{Version=[3],InitialVersion=[0],@ChgDeleted{Version=[3], |
| 2474 |
Text=[@key{pragma} @prag(Inline)(@Syn2{name} {, @Syn2{name}});]}} |
| 2475 |
@end{Syntax} |
| 2476 |
|
| 2477 |
@begin{Legality} |
| 2478 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 2479 |
@ChgDeleted{Version=[3],Text=[The @nt{pragma} shall apply to one or more |
| 2480 |
callable entities or generic subprograms.]} |
| 2481 |
@end{Legality} |
| 2482 |
|
| 2483 |
@begin{StaticSem} |
| 2484 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2485 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@ChgNote{Conditional leading} |
| 2486 |
@Chg{Version=[3],New=[For],Old=[If a @nt{pragma} Inline applies to]} |
| 2487 |
a callable entity@Chg{Version=[3],New=[ or],Old=[, |
| 2488 |
this indicates that inline expansion is desired for all calls |
| 2489 |
to that entity. |
| 2490 |
If a @nt{pragma} Inline applies to]} a generic subprogram, |
| 2491 |
@Chg{Version=[3],New=[the following language-defined |
| 2492 |
representation aspect may be specified:],Old=[this indicates that |
| 2493 |
inline expansion is desired for all calls to all instances of that |
| 2494 |
generic subprogram.]} |
| 2495 |
|
| 2496 |
@begin{Description} |
| 2497 |
@ChgRef{Version=[3],Kind=[Added]} |
| 2498 |
@ChgAdded{Version=[3],Text=[Inline@\The type of aspect Inline is Boolean. When |
| 2499 |
aspect Inline is True for a callable entity, inline expansion is desired for all |
| 2500 |
calls to that entity. When aspect Inline is True for a generic subprogram, |
| 2501 |
inline expansion is desired for all calls to all instances of that generic |
| 2502 |
subprogram.@AspectDefn{Inline}]} |
| 2503 |
|
| 2504 |
@ChgRef{Version=[3],Kind=[Added]} |
| 2505 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[If directly specified, the |
| 2506 |
@nt{aspect_definition} shall be a static expression. |
| 2507 |
@Redundant[This aspect is never inherited;] if not directly specified, |
| 2508 |
the aspect is False.]} |
| 2509 |
|
| 2510 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[Inline], |
| 2511 |
Text=[@ChgAdded{Version=[3],Text=[For efficiency, Inline calls are requested |
| 2512 |
for a subprogram.]}]} |
| 2513 |
|
| 2514 |
@end{Description} |
| 2515 |
|
| 2516 |
|
| 2517 |
@begin{Ramification} |
| 2518 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 2519 |
@ChgDeleted{Version=[3],Type=[Leading],Text=[Note that inline expansion is |
| 2520 |
desired no matter what name is used in the call. This allows one to request |
| 2521 |
inlining for only one of several overloaded subprograms as follows:]} |
| 2522 |
@begin{Example} |
| 2523 |
@ChgRef{Version=[3],Kind=[Deleted]} |
| 2524 |
@ChgDeleted{Version=[3],Text=[@key[package] IO @key[is] |
| 2525 |
@key[procedure] Put(X : @key[in] Integer); |
| 2526 |
@key[procedure] Put(X : @key[in] String); |
| 2527 |
@key[procedure] Put(X : @key[in] Character); |
| 2528 |
@key[private] |
| 2529 |
@key[procedure] Character_Put(X : @key[in] Character) @key[renames] Put; |
| 2530 |
@key[pragma] Inline(Character_Put); |
| 2531 |
@key[end] IO;]} |
| 2532 |
|
| 2533 |
@ChgRef{Version=[3],Kind=[Deleted]} |
| 2534 |
@ChgDeleted{Version=[3],Text=[@key[with] IO; @key[use] IO; |
| 2535 |
@key[procedure] Main @key[is] |
| 2536 |
I : Integer; |
| 2537 |
C : Character; |
| 2538 |
@key[begin] |
| 2539 |
... |
| 2540 |
Put(C); --@Examcom{ Inline expansion is desired.} |
| 2541 |
Put(I); --@Examcom{ Inline expansion is NOT desired.} |
| 2542 |
@key[end] Main;]} |
| 2543 |
@end{Example} |
| 2544 |
@end{Ramification} |
| 2545 |
@begin{Ramification} |
| 2546 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2547 |
The meaning of a subprogram can be changed by @Chg{Version=[3],New=[inline |
| 2548 |
expansion as requested by aspect],Old=[a @nt{pragma}]} Inline only |
| 2549 |
in the presence of failing checks |
| 2550 |
(see @RefSecNum{Exceptions and Optimization}). |
| 2551 |
@end{Ramification} |
| 2552 |
@end{StaticSem} |
| 2553 |
|
| 2554 |
@begin{ImplPerm} |
| 2555 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 2556 |
For each call, |
| 2557 |
an implementation is free to follow or to ignore the recommendation |
| 2558 |
@Chg{Version=[3],New=[determined],Old=[expressed]} by the |
| 2559 |
@Chg{Version=[3],New=[Inline aspect],Old=[@nt{pragma}]}. |
| 2560 |
@begin{Ramification} |
| 2561 |
Note, in particular, that the recommendation |
| 2562 |
cannot always be followed for a recursive call, |
| 2563 |
and is often infeasible for entries. |
| 2564 |
Note also that the implementation can inline calls even |
| 2565 |
when no such desire was expressed @Chg{Version=[3],New=[via the |
| 2566 |
Inline aspect],Old=[by a pragma]}, |
| 2567 |
so long as the semantics of the program remains unchanged. |
| 2568 |
@end{Ramification} |
| 2569 |
|
| 2570 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00309-01]} |
| 2571 |
@ChgRef{Version=[3],Kind=[DeletedAddedNoDelMsg],ARef=[AI05-0229-1]} |
| 2572 |
@ChgDeleted{Version=[3],Text=[@Chg{Version=[2],New=[An implementation may allow |
| 2573 |
a @nt{pragma} Inline that has an argument which is a @nt{direct_name} denoting a |
| 2574 |
@nt{subprogram_body} of the same @nt{declarative_part}.],Old=[]}]} |
| 2575 |
@begin{Reason} |
| 2576 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2577 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 2578 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[This is allowed for |
| 2579 |
Ada 83 compatibility. This is only a permission as this usage is considered |
| 2580 |
obsolescent.]}]} |
| 2581 |
@end{Reason} |
| 2582 |
@begin{Discussion} |
| 2583 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 2584 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 2585 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[We only need to allow |
| 2586 |
this in @nt{declarative_part}s, because a body is only allowed in another body, |
| 2587 |
and these all have @nt{declarative_part}s.]}]} |
| 2588 |
@end{Discussion} |
| 2589 |
@end{ImplPerm} |
| 2590 |
|
| 2591 |
@begin{Notes} |
| 2592 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 2593 |
@ChgDeleted{Version=[3],Text=[The @nt{name} in a @nt{pragma} Inline can denote |
| 2594 |
more than one entity in the case of overloading. |
| 2595 |
Such a @nt{pragma} applies to all of the denoted entities.]} |
| 2596 |
@end{Notes} |
| 2597 |
|
| 2598 |
@begin{Incompatible83} |
| 2599 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00309-01]} |
| 2600 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 2601 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[@Defn{incompatibilities with Ada 83} |
| 2602 |
A pragma Inline cannot refer to a @nt{subprogram_body} outside of that |
| 2603 |
body. The pragma can be given inside of the subprogram body. Ada 2005 |
| 2604 |
adds an @ImplPermName to allow this usage for compatibility (and |
| 2605 |
Ada 95 implementations also can use this permission), but |
| 2606 |
implementations do not have to allow such @nt{pragma}s.]}]} |
| 2607 |
@end{Incompatible83} |
| 2608 |
|
| 2609 |
@begin{Extend83} |
| 2610 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 2611 |
@ChgDeleted{Version=[3],Text=[@Defn{extensions to Ada 83} |
| 2612 |
A @nt{pragma} Inline is allowed inside a @nt{subprogram_body} if there |
| 2613 |
is no corresponding @nt{subprogram_declaration}. |
| 2614 |
This is for uniformity with other program unit pragmas.]} |
| 2615 |
@end{Extend83} |
| 2616 |
|
| 2617 |
@begin{Extend95} |
| 2618 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00309-01]} |
| 2619 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0229-1]} |
| 2620 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[@Defn{extensions to Ada 95} |
| 2621 |
@b[Amendment Correction:] Implementations are allowed to let @nt{Pragma} |
| 2622 |
Inline apply to a @nt{subprogram_body}.]}]} |
| 2623 |
@end{Extend95} |
| 2624 |
|
| 2625 |
@begin{Extend2005} |
| 2626 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 2627 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 2628 |
Aspect Inline is new; @nt{pragma} Inline is now obsolescent.]} |
| 2629 |
@end{Extend2005} |
| 2630 |
|
| 2631 |
|
| 2632 |
@RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM} |
| 2633 |
@LabeledClause{Subprogram Calls} |
| 2634 |
|
| 2635 |
@begin{Intro} |
| 2636 |
@Defn{subprogram call} |
| 2637 |
A @i{subprogram call} is either a @nt{procedure_call_statement} |
| 2638 |
or a @nt{function_call}; |
| 2639 |
@Redundant[it invokes the execution of the @nt{subprogram_body}. |
| 2640 |
The call specifies the association of the actual parameters, if any, |
| 2641 |
with formal parameters of the subprogram.] |
| 2642 |
@end{Intro} |
| 2643 |
|
| 2644 |
@begin{Syntax} |
| 2645 |
@Syn{lhs=<procedure_call_statement>,rhs=" |
| 2646 |
@SynI{procedure_}@Syn2{name}; |
| 2647 |
| @SynI{procedure_}@Syn2{prefix} @Syn2{actual_parameter_part};"} |
| 2648 |
|
| 2649 |
|
| 2650 |
@Syn{lhs=<function_call>,rhs=" |
| 2651 |
@SynI{function_}@Syn2{name} |
| 2652 |
| @SynI{function_}@Syn2{prefix} @Syn2{actual_parameter_part}"} |
| 2653 |
|
| 2654 |
@begin{Honest} |
| 2655 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]} |
| 2656 |
@ChgAdded{Version=[3],Text=[For the purpose of non-syntax rules, |
| 2657 |
infix operator calls are considered @nt{function_call}s. |
| 2658 |
See @RefSecNum{Overloading of Operators}.]} |
| 2659 |
@end{Honest} |
| 2660 |
|
| 2661 |
@Syn{lhs=<actual_parameter_part>,rhs=" |
| 2662 |
(@Syn2{parameter_association} {, @Syn2{parameter_association}})"} |
| 2663 |
|
| 2664 |
@Syn{lhs=<parameter_association>,rhs=" |
| 2665 |
[@SynI{formal_parameter_}@Syn2{selector_name} =>] @Syn2{explicit_actual_parameter}"} |
| 2666 |
|
| 2667 |
@Syn{lhs=<explicit_actual_parameter>,rhs="@Syn2{expression} | @SynI{variable_}@Syn2{name}"} |
| 2668 |
|
| 2669 |
@begin{SyntaxText} |
| 2670 |
@Defn{named association} |
| 2671 |
@Defn{positional association} |
| 2672 |
A @nt{parameter_association} is @i{named} or @i{positional} |
| 2673 |
according to whether or not the |
| 2674 |
@SynI{formal_@!parameter_}@!@nt{selector_@!name} is specified. |
| 2675 |
Any positional associations shall precede any named associations. |
| 2676 |
Named associations are not allowed if the @nt{prefix} in |
| 2677 |
a subprogram call is an @nt{attribute_@!reference}. |
| 2678 |
@begin{Ramification} |
| 2679 |
This means that the formal parameter names used in |
| 2680 |
describing predefined attributes are |
| 2681 |
to aid presentation of their semantics, but are not intended |
| 2682 |
for use in actual calls. |
| 2683 |
@end{Ramification} |
| 2684 |
@end{SyntaxText} |
| 2685 |
@end{Syntax} |
| 2686 |
|
| 2687 |
@begin{Resolution} |
| 2688 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00310-01]} |
| 2689 |
The @nt{name} or @nt{prefix} given in a @nt{procedure_call_statement} |
| 2690 |
shall resolve to denote |
| 2691 |
a callable entity that is a procedure, or an entry renamed |
| 2692 |
as (viewed as) a procedure. |
| 2693 |
The @nt{name} or @nt{prefix} given in a @nt{function_call} |
| 2694 |
shall resolve to denote |
| 2695 |
a callable entity that is a |
| 2696 |
function.@Chg{Version=[2],New=[ The @nt{name} or @nt{prefix} shall not |
| 2697 |
resolve to denote an abstract subprogram unless it is also a |
| 2698 |
dispatching subprogram.],Old=[]} |
| 2699 |
@Redundant[When there is an @nt<actual_@!parameter_@!part>, the @nt<prefix> |
| 2700 |
can be an @nt<implicit_@!dereference> of an access-to-subprogram |
| 2701 |
value.] |
| 2702 |
@begin{Discussion} |
| 2703 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00310-01]} |
| 2704 |
@ChgAdded{Version=[2],Text=[This rule is talking about dispatching operations |
| 2705 |
(which is a static concept) and not about dispatching calls (which is a |
| 2706 |
dynamic concept).]} |
| 2707 |
@end{Discussion} |
| 2708 |
@begin{Ramification} |
| 2709 |
The function can be an operator, |
| 2710 |
enumeration literal, attribute that is a function, etc. |
| 2711 |
@end{Ramification} |
| 2712 |
|
| 2713 |
A subprogram call shall contain at most one association for each |
| 2714 |
formal parameter. |
| 2715 |
Each formal parameter without an association shall have a |
| 2716 |
@nt{default_expression} (in the profile of the view denoted |
| 2717 |
by the @nt<name> or @nt<prefix>). |
| 2718 |
@Redundant[This rule is an overloading rule |
| 2719 |
(see @RefSecNum{The Context of Overload Resolution}).] |
| 2720 |
@begin{TheProof} |
| 2721 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0240-1]} |
| 2722 |
@ChgAdded{Version=[3],Text=[All @ResolutionTitle are overloading rules, |
| 2723 |
see @RefSecNum{The Context of Overload Resolution}.]} |
| 2724 |
@end{TheProof} |
| 2725 |
@end{Resolution} |
| 2726 |
@begin{RunTime} |
| 2727 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00345-01]} |
| 2728 |
@PDefn2{Term=[execution], Sec=(subprogram call)} |
| 2729 |
For the execution of a subprogram call, |
| 2730 |
the @nt{name} or @nt{prefix} of the call is evaluated, |
| 2731 |
and each @nt{parameter_@!association} is evaluated |
| 2732 |
(see @RefSecNum{Parameter Associations}). |
| 2733 |
If a @nt{default_@!expression} is used, |
| 2734 |
an implicit @nt{parameter_@!association} is assumed for this rule. |
| 2735 |
These evaluations are done in an arbitrary order. |
| 2736 |
The @nt{subprogram_@!body} is then executed@Chg{Version=[2],New=[, or a call |
| 2737 |
on an entry or protected subprogram is performed (see |
| 2738 |
@RefSecNum{Dispatching Operations of Tagged Types})],Old=[]}. |
| 2739 |
Finally, if the subprogram completes normally, then after it is left, |
| 2740 |
any necessary assigning back of formal to actual parameters occurs |
| 2741 |
(see @RefSecNum{Parameter Associations}).@PDefn2{Term=[arbitrary order],Sec=[allowed]} |
| 2742 |
|
| 2743 |
@begin{Discussion} |
| 2744 |
The implicit association for a default is only for this run-time rule. |
| 2745 |
At compile time, the visibility rules are applied to the default at |
| 2746 |
the place where it occurs, not at the place of a call. |
| 2747 |
@end{Discussion} |
| 2748 |
@begin{Honest} |
| 2749 |
If the subprogram is inherited, see @RefSec{Derived Types and Classes}. |
| 2750 |
|
| 2751 |
If the subprogram is protected, see @RefSec{Protected Subprograms and Protected Actions}. |
| 2752 |
|
| 2753 |
If the subprogram is really a renaming of an entry, see @RefSec{Entry Calls}. |
| 2754 |
|
| 2755 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00345-01]} |
| 2756 |
@ChgAdded{Version=[2],Text=[If the subprogram is implemented by an entry or |
| 2757 |
protected subprogram, it will be treated as a dispatching call to the |
| 2758 |
corresponding entry (see @RefSec{Entry Calls}) or protected subprogram (see |
| 2759 |
@RefSec{Protected Subprograms and Protected Actions}).]} |
| 2760 |
|
| 2761 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00348-01]} |
| 2762 |
Normally, the @nt{subprogram_body} that is executed by the above rule |
| 2763 |
is the one for the subprogram being called. |
| 2764 |
For an enumeration literal, |
| 2765 |
implicitly declared (but noninherited) subprogram, |
| 2766 |
@Chg{Version=[2],New=[null procedure, ],Old=[]}or an attribute that is |
| 2767 |
a subprogram, an implicit body is assumed. |
| 2768 |
For a dispatching call, |
| 2769 |
@RefSec{Dispatching Operations of Tagged Types} |
| 2770 |
defines which @nt{subprogram_body} is executed. |
| 2771 |
@end{Honest} |
| 2772 |
|
| 2773 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00407-01]} |
| 2774 |
@ChgAdded{Version=[2],Text=[If the @nt{name} or @nt{prefix} of a subprogram |
| 2775 |
call denotes a prefixed view (see @RefSecNum{Selected Components}), the |
| 2776 |
subprogram call is equivalent to a call on the underlying subprogram, with the |
| 2777 |
first actual parameter being provided by the @nt{prefix} of the prefixed view |
| 2778 |
(or the Access attribute of this @nt{prefix} if the first formal parameter is |
| 2779 |
an access parameter), and the remaining actual parameters given by the |
| 2780 |
@nt{actual_parameter_part}, if any.]} |
| 2781 |
|
| 2782 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 2783 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 2784 |
The exception Program_Error is raised at the point of a |
| 2785 |
@nt{function_call} if the function |
| 2786 |
completes normally without executing a |
| 2787 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}. |
| 2788 |
@begin{Discussion} |
| 2789 |
We are committing to raising the exception at the point |
| 2790 |
of call, for uniformity @em see AI83-00152. |
| 2791 |
This happens after the function is left, of course. |
| 2792 |
|
| 2793 |
Note that there is no name for suppressing this check, |
| 2794 |
since the check imposes no time overhead and minimal |
| 2795 |
space overhead (since it can usually be statically eliminated |
| 2796 |
as dead code). |
| 2797 |
@end{Discussion} |
| 2798 |
|
| 2799 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00231-01]} |
| 2800 |
A @nt{function_call} denotes a constant, as defined in |
| 2801 |
@RefSecNum{Return Statements}; the nominal subtype of the constant is |
| 2802 |
given by the @Chg{Version=[2],New=[nominal],Old=[result]} subtype of the |
| 2803 |
function@Chg{Version=[2],New=[ result],Old=[]}. |
| 2804 |
@PDefn2{Term=[nominal subtype], Sec=(of the result of a @nt<function_call>)} |
| 2805 |
@PDefn2{Term=[constant], Sec=(result of a @nt<function_call>)} |
| 2806 |
@end{RunTime} |
| 2807 |
|
| 2808 |
@begin{Examples} |
| 2809 |
@leading@keepnext@i{Examples of procedure calls:} |
| 2810 |
@begin{Example} |
| 2811 |
Traverse_Tree; --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 2812 |
Print_Header(128, Title, True); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 2813 |
|
| 2814 |
Switch(From => X, To => Next); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 2815 |
Print_Header(128, Header => Title, Center => True); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 2816 |
Print_Header(Header => Title, Center => True, Pages => 128); --@RI{ see @RefSecNum{Subprogram Declarations}} |
| 2817 |
@end{Example} |
| 2818 |
|
| 2819 |
@begin{WideAbove} |
| 2820 |
@leading@keepnext@i{Examples of function calls:} |
| 2821 |
@end{WideAbove} |
| 2822 |
@begin{Example} |
| 2823 |
Dot_Product(U, V) --@RI{ see @RefSecNum{Subprogram Declarations} and @RefSecNum{Subprogram Bodies}} |
| 2824 |
Clock --@RI{ see @RefSecNum{Delay Statements, Duration, and Time}} |
| 2825 |
F.@key[all] --@RI{ presuming F is of an access-to-subprogram type @em see @RefSecNum{Access Types}} |
| 2826 |
@end{Example} |
| 2827 |
|
| 2828 |
@begin{WideAbove} |
| 2829 |
@leading@keepnext@i{Examples of procedures with default expressions:} |
| 2830 |
@end{WideAbove} |
| 2831 |
@begin{Example} |
| 2832 |
@key[procedure] Activate(Process : @key[in] Process_Name; |
| 2833 |
After : @key[in] Process_Name := No_Process; |
| 2834 |
Wait : @key[in] Duration := 0.0; |
| 2835 |
Prior : @key[in] Boolean := False); |
| 2836 |
|
| 2837 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 2838 |
@key[procedure] Pair(Left, Right : @key[in] Person_Name := @key[new] Person@Chg{Version=[3],New=[(M)],Old=[]}); --@RI{ see @RefSecNum{Incomplete Type Declarations}} |
| 2839 |
@end{Example} |
| 2840 |
|
| 2841 |
@begin{WideAbove} |
| 2842 |
@leading@keepnext@i{Examples of their calls:} |
| 2843 |
@end{WideAbove} |
| 2844 |
@begin{Example} |
| 2845 |
Activate(X); |
| 2846 |
Activate(X, After => Y); |
| 2847 |
Activate(X, Wait => 60.0, Prior => True); |
| 2848 |
Activate(X, Y, 10.0, False); |
| 2849 |
|
| 2850 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 2851 |
Pair; |
| 2852 |
Pair(Left => @key[new] Person@Chg{Version=[3],New=[(F)],Old=[]}, Right => @key[new] Person@Chg{Version=[3],New=[(M)],Old=[]}); |
| 2853 |
@end{Example} |
| 2854 |
@end{Examples} |
| 2855 |
|
| 2856 |
@begin{Notes} |
| 2857 |
If a @nt{default_expression} is used for two or more parameters in a |
| 2858 |
multiple @nt{parameter_@!specification}, the @nt{default_@!expression} is |
| 2859 |
evaluated once for each omitted parameter. Hence in the above |
| 2860 |
examples, the two calls of Pair are equivalent. |
| 2861 |
@end{Notes} |
| 2862 |
|
| 2863 |
@begin{Examples} |
| 2864 |
@leading@keepnext@i{Examples of overloaded subprograms:} |
| 2865 |
@begin{Example} |
| 2866 |
@key[procedure] Put(X : @key[in] Integer); |
| 2867 |
@key[procedure] Put(X : @key[in] String); |
| 2868 |
|
| 2869 |
@key[procedure] Set(Tint : @key[in] Color); |
| 2870 |
@key[procedure] Set(Signal : @key[in] Light); |
| 2871 |
@end{Example} |
| 2872 |
|
| 2873 |
@begin{WideAbove} |
| 2874 |
@leading@keepnext@i{Examples of their calls:} |
| 2875 |
@end{WideAbove} |
| 2876 |
@begin{Example} |
| 2877 |
Put(28); |
| 2878 |
Put("no possible ambiguity here"); |
| 2879 |
|
| 2880 |
Set(Tint => Red); |
| 2881 |
Set(Signal => Red); |
| 2882 |
Set(Color'(Red)); |
| 2883 |
|
| 2884 |
--@RI{ Set(Red) would be ambiguous since Red may} |
| 2885 |
--@RI{ denote a value either of type Color or of type Light} |
| 2886 |
@end{Example} |
| 2887 |
@end{Examples} |
| 2888 |
|
| 2889 |
@begin{DiffWord83} |
| 2890 |
We have gotten rid of parameters @lquotes@;of the form of a type conversion@rquotes@; |
| 2891 |
(see RM83-6.4.1(3)). |
| 2892 |
The new view semantics of @nt{type_conversion}s allows us to use |
| 2893 |
normal @nt{type_conversion}s instead. |
| 2894 |
|
| 2895 |
We have moved wording about run-time semantics of parameter associations |
| 2896 |
to @RefSecNum{Parameter Associations}. |
| 2897 |
|
| 2898 |
We have moved wording about raising Program_Error for a function |
| 2899 |
that falls off the end to here from RM83-6.5. |
| 2900 |
@end{DiffWord83} |
| 2901 |
|
| 2902 |
@begin{Extend95} |
| 2903 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00310-01]} |
| 2904 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 2905 |
Nondispatching abstract operations are no longer considered when |
| 2906 |
resolving a subprogram call. That makes it possible to use @key{abstract} |
| 2907 |
to @lquotes@;undefine@rquotes@; a predefined operation for an untagged type. |
| 2908 |
That's especially helpful when defining custom arithmetic packages.]} |
| 2909 |
@end{Extend95} |
| 2910 |
|
| 2911 |
@begin{DiffWord95} |
| 2912 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00231-01]} |
| 2913 |
@ChgAdded{Version=[2],Text=[Changed the definition of the nominal subtype |
| 2914 |
of a @nt{function_call} to use the nominal subtype wording of |
| 2915 |
@RefSecNum{Subprogram Declarations}, to take into account |
| 2916 |
@nt{null_exclusion}s and access result types.]} |
| 2917 |
|
| 2918 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00345-01]} |
| 2919 |
@ChgAdded{Version=[2],Text=[Added wording to clarify that the meaning of |
| 2920 |
a call on a subprogram @lquotes@;implemented by@rquotes an entry or |
| 2921 |
protected operation is defined by |
| 2922 |
@RefSecNum{Dispatching Operations of Tagged Types}.]} |
| 2923 |
|
| 2924 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00407-01]} |
| 2925 |
@ChgAdded{Version=[2],Text=[Defined the meaning of a call on a prefixed |
| 2926 |
view of a subprogram (see @RefSecNum{Selected Components}).]} |
| 2927 |
@end{DiffWord95} |
| 2928 |
|
| 2929 |
|
| 2930 |
@LabeledSubClause{Parameter Associations} |
| 2931 |
|
| 2932 |
@begin{Intro} |
| 2933 |
@Redundant[@Defn{parameter passing} |
| 2934 |
A parameter association defines the association between an |
| 2935 |
actual parameter and a formal parameter.] |
| 2936 |
@end{Intro} |
| 2937 |
|
| 2938 |
@begin{MetaRules} |
| 2939 |
The parameter passing rules for @b(out) parameters |
| 2940 |
are designed to ensure that the parts of a type that have |
| 2941 |
implicit initial values (see @RefSecNum{Object Declarations}) |
| 2942 |
don't become @lquotes@;de-initialized@rquotes@; by |
| 2943 |
being passed as an @b(out) parameter. |
| 2944 |
|
| 2945 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 2946 |
@ChgAdded{Version=[3],Text=[For explicitly aliased parameters of functions, we |
| 2947 |
will ensure at the call site that a part of the parameter can be returned as |
| 2948 |
part of the function result without creating a dangling pointer. We do this with |
| 2949 |
accessibility checks at the call site that all actual objects of explicitly |
| 2950 |
aliased parameters live at least as long as the function result; then we can |
| 2951 |
allow them to be returned as access discriminants or anonymous access results, |
| 2952 |
as those have the master of the function result.]} |
| 2953 |
@end{MetaRules} |
| 2954 |
|
| 2955 |
@begin{Resolution} |
| 2956 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0118-1]} |
| 2957 |
The @SynI{formal_parameter_}@nt{selector_name} of |
| 2958 |
a@Chg{Version=[3],New=[ named],Old=[]} |
| 2959 |
@nt{parameter_@!association} shall resolve to denote a |
| 2960 |
@nt{parameter_@!specification} of the view being called@Chg{Version=[3],New=[; |
| 2961 |
@Defn{named association}@Defn{positional association}@Defn{named parameter association}@Defn{positional parameter association}this |
| 2962 |
is the formal parameter of the association. The formal parameter for a |
| 2963 |
positional @nt{parameter_@!association} is the parameter with the corresponding |
| 2964 |
position in the formal part of the view being called],Old=[]}. |
| 2965 |
|
| 2966 |
@begin{Honest} |
| 2967 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0118-1]} |
| 2968 |
@ChgAdded{Version=[3],Text=[For positional parameters, the |
| 2969 |
@ldquote@;corresponding position@rdquote is calculated after any |
| 2970 |
transformation of prefixed views.]} |
| 2971 |
@end{Honest} |
| 2972 |
|
| 2973 |
@Defn2{Term=[actual parameter], Sec=(for a formal parameter)} |
| 2974 |
The @i(actual parameter) is either the @nt<explicit_actual_parameter> |
| 2975 |
given in a @nt<parameter_association> for a given |
| 2976 |
formal parameter, or the corresponding @nt<default_expression> |
| 2977 |
if no @nt<parameter_association> is given for the formal parameter. |
| 2978 |
@Defn2{Term=[expected type], Sec=(actual parameter)} |
| 2979 |
The expected type for an actual parameter is the |
| 2980 |
type of the corresponding formal parameter. |
| 2981 |
@begin{Honest} |
| 2982 |
The corresponding @nt<default_expression> is the one of the |
| 2983 |
corresponding formal parameter |
| 2984 |
in the profile of the view denoted by the @nt<name> or |
| 2985 |
@nt<prefix> of the call. |
| 2986 |
@end{Honest} |
| 2987 |
|
| 2988 |
If the mode is @key(in), |
| 2989 |
the actual is interpreted as an @nt{expression}; |
| 2990 |
otherwise, the actual is interpreted only as a @nt{name}, if possible. |
| 2991 |
@begin{Ramification} |
| 2992 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]} |
| 2993 |
This formally resolves the ambiguity present in the syntax rule |
| 2994 |
for @nt<explicit_actual_parameter>. |
| 2995 |
@Chg{Version=[4],New=[This matters as an @nt{expression} that is a |
| 2996 |
@nt{name} is evaluated and represents a value while a @nt{name} by itself |
| 2997 |
can be an object; if the mode is not @key[in], we want the parameter to |
| 2998 |
interpreted as an object.],Old=[]} Note that we don't actually require |
| 2999 |
that the actual be a @nt<name> if the mode is not @key(in); |
| 3000 |
we do that below. |
| 3001 |
|
| 3002 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0005-1]} |
| 3003 |
@ChgAdded{Version=[4],Text=[This wording uses "interpreted as" rather than |
| 3004 |
"shall be" so that this rule is not used to resolve overloading; it is |
| 3005 |
solely about evaluation as described above. We definitely do not want |
| 3006 |
to allow oddities like the presence of parentheses requiring the selection of |
| 3007 |
an @key[in] formal parameter as opposed to an otherwise matching @key[in out] |
| 3008 |
parameter.]} |
| 3009 |
@end{Ramification} |
| 3010 |
@end{Resolution} |
| 3011 |
|
| 3012 |
@begin{Legality} |
| 3013 |
If the mode is @key(in out) or @key(out), |
| 3014 |
the actual shall be a @nt<name> that denotes a variable. |
| 3015 |
@begin{Discussion} |
| 3016 |
We no longer need @lquotes@;or a |
| 3017 |
@nt{type_conversion} whose argument is the @nt{name} of a variable,@rquotes@; |
| 3018 |
because a @nt{type_conversion} is now a @nt{name}, and a |
| 3019 |
@nt{type_conversion} of a variable is a variable. |
| 3020 |
@end{Discussion} |
| 3021 |
@begin{Reason} |
| 3022 |
@leading@;The requirement that the actual be a (variable) @nt<name> is not |
| 3023 |
an overload resolution rule, since |
| 3024 |
we don't want the difference between @nt<expression> and |
| 3025 |
@nt{name} to be used to resolve overloading. |
| 3026 |
For example: |
| 3027 |
@begin{Example} |
| 3028 |
procedure Print(X : @key[in] Integer; Y : @key[in] Boolean := True); |
| 3029 |
procedure Print(Z : @key[in out] Integer); |
| 3030 |
. . . |
| 3031 |
Print(3); --@RI{ Ambiguous!} |
| 3032 |
@end{Example} |
| 3033 |
|
| 3034 |
The above call to Print is ambiguous even though the call is |
| 3035 |
not compatible with the second Print which requires an actual |
| 3036 |
that is a (variable) @nt<name> (@lquotes@;3@rquotes@; is an @nt<expression>, not |
| 3037 |
a @nt<name>). This requirement is a legality rule, so overload |
| 3038 |
resolution fails before it is considered, meaning that the call |
| 3039 |
is ambiguous. |
| 3040 |
@end{Reason} |
| 3041 |
|
| 3042 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 3043 |
@ChgAdded{Version=[4],Text=[If the mode is @key[out], the actual parameter is a |
| 3044 |
view conversion, and the type of the formal parameter is an access type or |
| 3045 |
a scalar type that has the Default_Value aspect specified, then]} |
| 3046 |
@begin{Itemize} |
| 3047 |
@ChgRef{Version=[4],Kind=[Added]} |
| 3048 |
@ChgAdded{Version=[4],Text=[there shall exist a type (other than a root |
| 3049 |
numeric type) that is an ancestor of both the target type and the operand |
| 3050 |
type; and]} |
| 3051 |
|
| 3052 |
@ChgRef{Version=[4],Kind=[Added]} |
| 3053 |
@ChgAdded{Version=[4],Text=[in the case of a scalar type, the type of the |
| 3054 |
operand of the conversion shall have the Default_Value aspect specified.]} |
| 3055 |
@end{Itemize} |
| 3056 |
|
| 3057 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 3058 |
@ChgAdded{Version=[4],Text=[@PDefn{generic contract issue} |
| 3059 |
In addition to the places where |
| 3060 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 3061 |
these rules also apply in the private part of an instance of a generic unit.]} |
| 3062 |
|
| 3063 |
@begin{Reason} |
| 3064 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 3065 |
@ChgAdded{Version=[4],Text=[These rules are needed in order to ensure that a |
| 3066 |
well-defined parameter value is passed.]} |
| 3067 |
@end{Reason} |
| 3068 |
|
| 3069 |
|
| 3070 |
|
| 3071 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0102-1],ARef=[AI05-0142-4]} |
| 3072 |
@leading@;@Chg{Version=[3],New=[If the formal parameter is an explicitly aliased |
| 3073 |
parameter, the type of the actual parameter shall be tagged or the actual |
| 3074 |
parameter shall be an aliased view of an object. Further, if the formal |
| 3075 |
parameter subtype @i{F} is untagged:], |
| 3076 |
Old=[The type of the actual parameter associated with an access parameter |
| 3077 |
shall be convertible (see @RefSecNum{Type Conversions}) |
| 3078 |
to its anonymous access type. |
| 3079 |
@PDefn2{Term=[convertible],Sec=(required)}]} |
| 3080 |
|
| 3081 |
@begin{Itemize} |
| 3082 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3083 |
@ChgAdded{Version=[3],Text=[the subtype @i{F} shall statically match the nominal |
| 3084 |
subtype of the actual object; or]} |
| 3085 |
|
| 3086 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3087 |
@ChgAdded{Version=[3],Text=[the subtype @i{F} shall be unconstrained, discriminated |
| 3088 |
in its full view, and unconstrained in any partial view.]} |
| 3089 |
@end{Itemize} |
| 3090 |
|
| 3091 |
@begin{Ramification} |
| 3092 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3093 |
@ChgAdded{Version=[3],Text=[Tagged objects (and tagged @nt{aggregate}s for @key[in] |
| 3094 |
parameters) do not need to be aliased. This matches the behavior of unaliased |
| 3095 |
formal parameters of tagged types, which allow 'Access to be taken of the |
| 3096 |
formal parameter regardless of the form of the actual parameter.]} |
| 3097 |
@end{Ramification} |
| 3098 |
|
| 3099 |
@begin{Reason} |
| 3100 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3101 |
@ChgAdded{Version=[3],Text=[We need the subtype check on untagged actual |
| 3102 |
parameters so that the requirements of 'Access are not lost. 'Access makes its |
| 3103 |
checks against the nominal subtype of its prefix, and parameter passing can |
| 3104 |
change that subtype. But we don't want this parameter passing to change the |
| 3105 |
objects that would be allowed as the prefix of 'Access. This is particularly |
| 3106 |
important for arrays, where we don't want to require any additional |
| 3107 |
implementation burden.]} |
| 3108 |
@end{Reason} |
| 3109 |
|
| 3110 |
@begin{Discussion} |
| 3111 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]} |
| 3112 |
@ChgAdded{Version=[4],Text=[We assume the worst in a generic body whether |
| 3113 |
or not a formal subtype has a constrained partial view; specifically, in a |
| 3114 |
generic body a discriminated subtype is considered to have a constrained |
| 3115 |
partial view if it is a descendant of an untagged generic formal private |
| 3116 |
or derived type (see @RefSecNum{Formal Private and Derived Types} for the |
| 3117 |
formal definition of this rule).]} |
| 3118 |
@end{Discussion} |
| 3119 |
|
| 3120 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0095-1]} |
| 3121 |
@ChgAdded{Version=[4],Text=[@PDefn{generic contract issue} |
| 3122 |
In addition to the places where |
| 3123 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 3124 |
these rules also apply in the private part of an instance of a generic unit.]} |
| 3125 |
|
| 3126 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0234-1]} |
| 3127 |
@ChgAdded{Version=[3],Text=[In a function call, the accessibility level of the |
| 3128 |
actual object for each explicitly aliased parameter shall not be statically |
| 3129 |
deeper than the accessibility level of the master of the call |
| 3130 |
(see @RefSecNum{Operations of Access Types}).]} |
| 3131 |
|
| 3132 |
@begin{Discussion} |
| 3133 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3134 |
@ChgAdded{Version=[3],Text=[Since explicitly aliased parameters are either |
| 3135 |
tagged or required to be objects, there is always an object (possibly |
| 3136 |
anonymous) to talk about. This is discussing the static accessibility level of |
| 3137 |
the actual object; it does not depend on any runtime information (for instance |
| 3138 |
when the actual object is a formal parameter of another subprogram, it does |
| 3139 |
not depend on the actual parameter of that other subprogram).]} |
| 3140 |
@end{Discussion} |
| 3141 |
|
| 3142 |
@begin{Ramification} |
| 3143 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3144 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0095-1]} |
| 3145 |
@ChgAdded{Version=[3],Text=[This accessibility check (and its dynamic cousin |
| 3146 |
as well) can only fail if the @Chg{Version=[4],New=[master of the function |
| 3147 |
call (which is defined in the Heart of Darkness, or |
| 3148 |
@RefSecNum{Operations of Access Types} if you prefer) is different than |
| 3149 |
the master directly enclosing the call],Old=[function call is used to directly initialize a |
| 3150 |
built-in-place object with a master different than that enclosing the call]}. |
| 3151 |
The @Chg{Version=[4],New=[most likely],Old=[only]} place |
| 3152 |
@Chg{Version=[4],New=[where this will occur],Old=[all of those conditions |
| 3153 |
exist]} is in the initializer of an @nt{allocator}; in |
| 3154 |
@Chg{Version=[4],New=[almost ],Old=[]}all other cases this check will always |
| 3155 |
pass.]} |
| 3156 |
@end{Ramification} |
| 3157 |
|
| 3158 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 3159 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Two @nt{name}s are |
| 3160 |
@i{known to denote the same object} if:@Defn{known to denote the same object}]} |
| 3161 |
|
| 3162 |
@begin{Itemize} |
| 3163 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3164 |
@ChgAdded{Version=[3],Text=[both @nt{name}s statically denote the same |
| 3165 |
stand-alone object or parameter; or]} |
| 3166 |
|
| 3167 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3168 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are @nt{selected_component}s, |
| 3169 |
their @nt{prefix}es are known to denote the same object, and their |
| 3170 |
@nt{selector_name}s denote the same component; or]} |
| 3171 |
|
| 3172 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3173 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are dereferences (implicit or |
| 3174 |
explicit) and the dereferenced @nt{name}s are known to denote the same object; |
| 3175 |
or]} |
| 3176 |
|
| 3177 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3178 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are @nt{indexed_component}s, their |
| 3179 |
@nt{prefix}es are known to denote the same object, and each of the pairs of |
| 3180 |
corresponding index values are either both static expressions with the same |
| 3181 |
static value or both @nt{name}s that are known to denote the same object; or]} |
| 3182 |
|
| 3183 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3184 |
@ChgAdded{Version=[3],Text=[both @nt{name}s are @nt{slice}s, their |
| 3185 |
@nt{prefix}es are known to denote the same object, and the two @nt{slice}s have |
| 3186 |
statically matching index constraints; or]} |
| 3187 |
|
| 3188 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3189 |
@ChgAdded{Version=[3],Text=[one of the two @nt{name}s statically denotes a |
| 3190 |
renaming declaration whose renamed @SynI{object_}@nt{name} is known to denote |
| 3191 |
the same object as the other, the @nt{prefix} of any dereference within |
| 3192 |
the renamed @SynI{object_}@nt{name} is not a variable, and any @nt{expression} |
| 3193 |
within the renamed @SynI{object_}@nt{name} contains no references to variables |
| 3194 |
nor calls on nonstatic functions.]} |
| 3195 |
@begin{Reason} |
| 3196 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3197 |
@ChgAdded{Version=[3],Type=[Leading],Text=[This exposes known renamings of |
| 3198 |
slices, indexing, and so on to this definition. In particular, if we have]} |
| 3199 |
@begin{Example} |
| 3200 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3201 |
@ChgAdded{Version=[3],Type=[Leading],Text=[C : Character @key[renames] S(1);]} |
| 3202 |
@end{Example} |
| 3203 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3204 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[then C and S(1) are known to |
| 3205 |
denote the same object.]} |
| 3206 |
|
| 3207 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3208 |
@ChgAdded{Version=[3],Type=[Leading],Text=[We need the requirement that no |
| 3209 |
variables occur in the @nt{prefix}es of dereferences and in (index) |
| 3210 |
@nt{expression}s of the renamed object in order to avoid problems from later |
| 3211 |
changes to those parts of renamed names. Consider:]} |
| 3212 |
|
| 3213 |
@begin{Example} |
| 3214 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3215 |
@ChgAdded{Version=[3],Type=[Leading],Text=[ @key[type] Ref @key[is access] Some_Type; |
| 3216 |
Ptr : Ref := @key[new] Some_Type'(...); |
| 3217 |
X : Some_Type @key[renames] Ptr.@key[all]; |
| 3218 |
@key[begin] |
| 3219 |
Ptr := @key[new] Some_Type'(...); |
| 3220 |
P (Func_With_Out_Params (Ptr.@key[all]), X);]} |
| 3221 |
@end{Example} |
| 3222 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3223 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[X and Ptr.@key[all] should not be |
| 3224 |
known to denote the same object, since they denote different allocated objects |
| 3225 |
(and this is not an unreasonable thing to do).]} |
| 3226 |
@end{Reason} |
| 3227 |
|
| 3228 |
@begin{Honest} |
| 3229 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3230 |
@ChgAdded{Version=[3],Type=[Leading],Text=[The exclusion of variables from |
| 3231 |
renamed object_names is not enough to prevent altering the value of the name |
| 3232 |
or expression by another access path. For instance, both @key[in] parameters |
| 3233 |
passed by reference and access-to-constant values can designate variables. For |
| 3234 |
the intended use of "known to be the same object", this is OK; the |
| 3235 |
modification via another access path is very tricky and it is OK to reject |
| 3236 |
code that would be buggy except for the tricky code. Assuming Element is an |
| 3237 |
elementary type, consider the following example:]} |
| 3238 |
@begin{Example} |
| 3239 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3240 |
@ChgAdded{Version=[3],Text=[Global : Tagged_Type;]} |
| 3241 |
|
| 3242 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3243 |
@ChgAdded{Version=[3],Text=[@key{procedure} Foo (Param : @key{in} Tagged_Type := Global) @key{is} |
| 3244 |
X : Element @key{renames} Some_Global_Array (Param.C); |
| 3245 |
@key{begin} |
| 3246 |
Global.C := Global.C + 1; |
| 3247 |
Swap (X, Some_Global_Array (Param.C));]} |
| 3248 |
@end{Example} |
| 3249 |
|
| 3250 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3251 |
@ChgAdded{Version=[3],Text=[The rules will flag the call of procedure Swap |
| 3252 |
as illegal, since X and Some_Global_Array (Parameter.C) are known to denote |
| 3253 |
the same object (even though they will actually represent different objects if |
| 3254 |
Param = Global). But this is only incorrect if the parameter actually is |
| 3255 |
Global and not some other value; the error could exist for some calls. So this |
| 3256 |
flagging seems harmless.]} |
| 3257 |
|
| 3258 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3259 |
@ChgAdded{Version=[3],Text=[Similar examples can be constructed using |
| 3260 |
stand-alone composite constants with controlled or immutably limited |
| 3261 |
components, and (as previously noted) with dereferences of access-to-constant |
| 3262 |
values. Even when these examples flag a call incorrectly, that call depends |
| 3263 |
on very tricky code (modifying the value of a constant); the code is likely |
| 3264 |
to confuse future maintainers as well and thus we do not mind rejecting it.]} |
| 3265 |
@end{Honest} |
| 3266 |
|
| 3267 |
@end{Itemize} |
| 3268 |
|
| 3269 |
@begin{Discussion} |
| 3270 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3271 |
@ChgAdded{Version=[3],Text=[Whether or not @nt{name}s or @nt{prefix}es are |
| 3272 |
known to denote the same object is determined statically. If the name |
| 3273 |
contains some dynamic portion other than a dereference, @nt{indexed_component}, or |
| 3274 |
@nt{slice}, it is not "known to denote the same object".]} |
| 3275 |
|
| 3276 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3277 |
@ChgAdded{Version=[3],Text=[These rules make no attempt to handle slices of |
| 3278 |
objects that are known to be the same when the slices have dynamic bounds |
| 3279 |
(other than the trivial case of bounds being defined by the same subtype), |
| 3280 |
even when the bounds could be proven to be the same, as it is just too complex |
| 3281 |
to get right and these rules are intended to be conservative.]} |
| 3282 |
@end{Discussion} |
| 3283 |
|
| 3284 |
@begin{Ramification} |
| 3285 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3286 |
@ChgAdded{Version=[3],Type=[Leading],Text=["Known to denote the same object" |
| 3287 |
is intended to be an equivalence relationship, that is, it is reflexive, |
| 3288 |
symmetric, and transitive. We believe this follows from the rules. |
| 3289 |
For instance, given the following declarations:]} |
| 3290 |
@begin{Example} |
| 3291 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3292 |
@ChgAdded{Version=[3],Type=[Leading],Text=[S : String(1..10); |
| 3293 |
ONE : @key[constant] Natural := 1; |
| 3294 |
R : Character @key[renames] S(1);]} |
| 3295 |
@end{Example} |
| 3296 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3297 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[the names R and S(1) are known to |
| 3298 |
denote the same object by the sixth bullet, and S(1) and S(ONE) are known to |
| 3299 |
denote the same object by the fourth bullet, so using the sixth bullet on |
| 3300 |
R and S(ONE), we simply have to test S(1) vs. S(ONE), which we already know |
| 3301 |
denote the same object.]} |
| 3302 |
@end{Ramification} |
| 3303 |
|
| 3304 |
|
| 3305 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 3306 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Two @nt{name}s are @i{known to |
| 3307 |
refer to the same object} if @Defn{known to refer to the same object}]} |
| 3308 |
@begin{Itemize} |
| 3309 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3310 |
@ChgAdded{Version=[3],Text=[The two @nt{name}s are known to denote the same object; or]} |
| 3311 |
|
| 3312 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3313 |
@ChgAdded{Version=[3],Text=[One of the @nt{name}s is a @nt{selected_component}, |
| 3314 |
@nt{indexed_component}, or @nt{slice} and its @nt{prefix} is known to refer |
| 3315 |
to the same object as the other @nt{name}; or]} |
| 3316 |
|
| 3317 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3318 |
@ChgAdded{Version=[3],Text=[One of the two @nt{name}s statically denotes a |
| 3319 |
renaming declaration whose renamed @SynI{object_}@nt{name} is known to refer |
| 3320 |
to the same object as the other @nt{name}.]} |
| 3321 |
@end{Itemize} |
| 3322 |
|
| 3323 |
@begin{Reason} |
| 3324 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3325 |
@ChgAdded{Version=[3],Text=[This ensures that names Prefix.Comp and Prefix are |
| 3326 |
known to refer to the same object for the purposes of the rules below. This |
| 3327 |
intentionally does not include dereferences; we only want to worry about |
| 3328 |
accesses to the same object, and a dereference changes the object in question. |
| 3329 |
(There is nothing shared between an access value and the object it |
| 3330 |
designates.)]} |
| 3331 |
@end{Reason} |
| 3332 |
|
| 3333 |
|
| 3334 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 3335 |
@ChgAdded{Version=[3],Type=[Leading],Text=[ |
| 3336 |
If a call @i<C> has two or more parameters of mode @key[in out] or @key[out] that |
| 3337 |
are of an elementary type, then the call is legal only if:]} |
| 3338 |
|
| 3339 |
@begin{Itemize} |
| 3340 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3341 |
@ChgAdded{Version=[3],Text=[For each @nt{name} @i<N> that is passed as a parameter of mode @key[in out] or |
| 3342 |
@key[out] to the call @i<C>, there is no other @nt{name} among the other |
| 3343 |
parameters of mode @key[in out] or @key[out] to @i<C> that is known to denote the |
| 3344 |
same object.]} |
| 3345 |
|
| 3346 |
@begin{Honest} |
| 3347 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3348 |
@ChgAdded{Version=[3],Text=[This means @i{visibly} an elementary type; it does |
| 3349 |
not include partial views of elementary types (partial views are always |
| 3350 |
composite). That's necessary to avoid having @LegalityTitle depend on the |
| 3351 |
contents of the private part.]} |
| 3352 |
@end{Honest} |
| 3353 |
@end{Itemize} |
| 3354 |
|
| 3355 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 3356 |
@ChgAdded{Version=[3],Type=[Leading],Text=[If a construct @i<C> has two or more |
| 3357 |
direct constituents that are @nt{name}s or @nt{expression}s whose evaluation may |
| 3358 |
occur in an arbitrary order, at least one of which contains a function call with |
| 3359 |
an @key[in out] or @key[out] parameter, then the construct is legal only if:]} |
| 3360 |
|
| 3361 |
@begin{Ramification} |
| 3362 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3363 |
@ChgAdded{Version=[3],Text=[All of the places where the language allows an |
| 3364 |
arbitrary order can be found by looking in the index under "arbitrary order, |
| 3365 |
allowed". Note that this listing includes places that don't involve |
| 3366 |
@nt{name}s or @nt{expression}s (such as checks or finalization).]} |
| 3367 |
@end{Ramification} |
| 3368 |
|
| 3369 |
@begin{Itemize} |
| 3370 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3371 |
@ChgAdded{Version=[3],Text=[For each name @i<N> that is passed as a parameter of mode @key[in out] or |
| 3372 |
@key[out] to some inner function call @i<C2> (not including the construct @i<C> |
| 3373 |
itself), there is no other @nt{name} anywhere within a direct constituent of the |
| 3374 |
construct @i<C> other than the one containing @i<C2>, that is known to refer to |
| 3375 |
the same object.]} |
| 3376 |
@end{Itemize} |
| 3377 |
|
| 3378 |
@begin{Ramification} |
| 3379 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3380 |
@ChgAdded{Version=[3],Text=[This requirement cannot fail for a procedure |
| 3381 |
or entry call alone; there must be at least one function with an @key[in out] |
| 3382 |
or @key[out] parameter called as part of a parameter expression of the call in |
| 3383 |
order for it to fail.]} |
| 3384 |
@end{Ramification} |
| 3385 |
|
| 3386 |
@begin{Reason} |
| 3387 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3388 |
@ChgAdded{Version=[3],Text=[These rules prevent obvious cases of dependence on |
| 3389 |
the order of evaluation of @nt{name}s or @nt{expression}s. Such dependence is |
| 3390 |
usually a bug, and in any case, is not portable to another implementation (or |
| 3391 |
even another optimization setting).]} |
| 3392 |
|
| 3393 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3394 |
@ChgAdded{Version=[3],Text=[In the case that the top-level construct C is a |
| 3395 |
call, these rules do not require checks for most @key[in out] parameters, as |
| 3396 |
the rules about evaluation of calls prevent problems. Similarly, we do not |
| 3397 |
need checks for short circuit operations or other operations with a defined |
| 3398 |
order of evaluation. The rules about arbitrary order (see |
| 3399 |
@RefSecNum{Method of Description and Syntax Notation}) allow evaluating |
| 3400 |
parameters and writing parameters back in an arbitrary order, but not |
| 3401 |
interleaving of evaluating |
| 3402 |
parameters of one call with writing parameters back from another @em that |
| 3403 |
would not correspond to any allowed sequential order.]} |
| 3404 |
@end{Reason} |
| 3405 |
|
| 3406 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0144-2]} |
| 3407 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For the purposes of checking this rule:]} |
| 3408 |
|
| 3409 |
@begin{Itemize} |
| 3410 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3411 |
@ChgAdded{Version=[3],Text=[For an array @nt{aggregate}, an @nt{expression} |
| 3412 |
associated with a @nt{discrete_choice_list} that has two or more discrete |
| 3413 |
choices, or that has a nonstatic range, is considered as two or more separate |
| 3414 |
occurrences of the @nt{expression};]} |
| 3415 |
|
| 3416 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3417 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For a record @nt{aggregate}:]} |
| 3418 |
|
| 3419 |
@begin{InnerItemize} |
| 3420 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3421 |
@ChgAdded{Version=[3],Text=[The @nt{expression} of a |
| 3422 |
@nt{record_component_association} is considered to occur once for each |
| 3423 |
associated component; and]} |
| 3424 |
|
| 3425 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3426 |
@ChgAdded{Version=[3],Text=[The @nt{default_expression} for each |
| 3427 |
@nt{record_component_association} |
| 3428 |
with <> for which the associated component has a @nt{default_expression} |
| 3429 |
is considered part of the @nt{aggregate};]} |
| 3430 |
@end{InnerItemize} |
| 3431 |
|
| 3432 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3433 |
@ChgAdded{Version=[3],Text=[For a call, any @nt{default_expression} evaluated as |
| 3434 |
part of the call is considered part of the call.]} |
| 3435 |
@end{Itemize} |
| 3436 |
|
| 3437 |
@begin{Ramification} |
| 3438 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3439 |
@ChgAdded{Version=[3],Text=[We do not check expressions that are evaluated only because |
| 3440 |
of a component initialized by default in an aggregate (via <>).]} |
| 3441 |
@end{Ramification} |
| 3442 |
@end{Legality} |
| 3443 |
|
| 3444 |
@begin{RunTime} |
| 3445 |
@leading@keepnext@PDefn2{Term=[evaluation], Sec=(parameter_association)} |
| 3446 |
For the evaluation of a @nt{parameter_association}: |
| 3447 |
@begin{Itemize} |
| 3448 |
The actual parameter is first evaluated. |
| 3449 |
|
| 3450 |
For an access parameter, |
| 3451 |
the @nt{access_definition} is elaborated, |
| 3452 |
which creates the anonymous access type. |
| 3453 |
|
| 3454 |
For a parameter @Redundant[(of any mode)] that is passed by reference |
| 3455 |
(see @RefSecNum{Formal Parameter Modes}), |
| 3456 |
a view conversion of the actual parameter to the nominal subtype |
| 3457 |
of the formal parameter is evaluated, |
| 3458 |
and the formal parameter denotes that conversion. |
| 3459 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 3460 |
@begin{Discussion} |
| 3461 |
We are always allowing sliding, even for [@key(in)] @key(out) by-reference |
| 3462 |
parameters. |
| 3463 |
@end{Discussion} |
| 3464 |
|
| 3465 |
@Defn2{Term=[assignment operation], Sec=(during evaluation of a |
| 3466 |
@nt{parameter_association})} |
| 3467 |
For an @key(in) or @key(in out) parameter that is passed |
| 3468 |
by copy (see @RefSecNum{Formal Parameter Modes}), |
| 3469 |
the formal parameter object is created, |
| 3470 |
and the value of the actual parameter is converted to the |
| 3471 |
nominal subtype of the formal parameter |
| 3472 |
and assigned to the formal. |
| 3473 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 3474 |
@begin{Ramification} |
| 3475 |
The conversion mentioned here is a value conversion. |
| 3476 |
@end{Ramification} |
| 3477 |
|
| 3478 |
@leading@keepnext@;For an @key(out) parameter that is passed by copy, |
| 3479 |
the formal parameter object is created, and: |
| 3480 |
@begin(itemize) |
| 3481 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0153-3],ARef=[AI05-0196-1]} |
| 3482 |
For an access type, the formal parameter is initialized |
| 3483 |
from the value of the actual, without @Chg{Version=[3],New=[checking that the |
| 3484 |
value satisfies any constraint, any predicate, or any exclusion of the null |
| 3485 |
value],Old=[a constraint check]}; |
| 3486 |
@begin{Reason} |
| 3487 |
This preserves the @MetaRulesName that an object of an access type |
| 3488 |
is always initialized with a @lquotes@;reasonable@rquotes@; value. |
| 3489 |
@end{Reason} |
| 3490 |
|
| 3491 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0153-3],ARef=[AI05-0228-1]} |
| 3492 |
@ChgRef{Version=[4],Kind=[RevisedAdded],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 3493 |
@ChgAdded{Version=[4],Type=[Leading],Text=[]}@Comment{To add conditional leading} |
| 3494 |
@ChgAdded{Version=[3],Text=[For a scalar type that has the Default_Value aspect |
| 3495 |
specified, the formal parameter is initialized from the value of the actual, |
| 3496 |
without checking that the value satisfies any constraint or any |
| 3497 |
predicate@Chg{Version=[4],New=[. Furthermore, if the actual |
| 3498 |
parameter is a view conversion and either],Old=[;]}]} |
| 3499 |
|
| 3500 |
@begin{Itemize} |
| 3501 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1]} |
| 3502 |
@ChgAdded{Version=[4],Text=[there exists no type (other than a root |
| 3503 |
numeric type) that is an ancestor of both the target type and the type |
| 3504 |
of the operand of the conversion; or]} |
| 3505 |
|
| 3506 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1]} |
| 3507 |
@ChgAdded{Version=[4],Text=[the Default_Value aspect is unspecified for |
| 3508 |
the type of the operand of the conversion]} |
| 3509 |
@end{Itemize} |
| 3510 |
|
| 3511 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0074-1]} |
| 3512 |
@ChgAdded{Version=[4],NoPrefix=[T],Text=[then Program_Error |
| 3513 |
is raised;@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}]} |
| 3514 |
|
| 3515 |
@begin{Reason} |
| 3516 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3517 |
@ChgAdded{Version=[3],Text=[This preserves the @MetaRulesName that all objects |
| 3518 |
of a type with an implicit initial value are initialized. This is important so |
| 3519 |
that a programmer can guarantee that all objects of a scalar type have a valid |
| 3520 |
value with a carefully chosen Default_Value.]} |
| 3521 |
@end{Reason} |
| 3522 |
|
| 3523 |
@begin{ImplNote} |
| 3524 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 3525 |
@ChgAdded{Version=[3],Text=[This rule means that @b<out> parameters of a |
| 3526 |
subtype @i<T> with a specified Default_Value need to be large enough to |
| 3527 |
support any possible value of the base type of @i<T>. In contrast, a type that |
| 3528 |
does not have a Default_Value only need support the size of the subtype (since |
| 3529 |
no values are passed in).]} |
| 3530 |
@end{ImplNote} |
| 3531 |
|
| 3532 |
@begin{Discussion} |
| 3533 |
@ChgRef{Version=[4],Kind=[AddedNormal]} |
| 3534 |
@ChgAdded{Version=[4],Text=[The Program_Error case can only occur in the |
| 3535 |
body of an instance of a generic unit. @LegalityTitle will catch all other |
| 3536 |
cases. Implementations that macro-expand generics |
| 3537 |
can always detect this case when the enclosing instance body is expanded.]} |
| 3538 |
@end{Discussion} |
| 3539 |
|
| 3540 |
For a composite type with discriminants or |
| 3541 |
that has implicit initial values for any subcomponents |
| 3542 |
(see @RefSecNum{Object Declarations}), |
| 3543 |
the behavior is as for an @key[in out] parameter |
| 3544 |
passed by copy. |
| 3545 |
@begin{Reason} |
| 3546 |
This ensures that no part of an object of such a type |
| 3547 |
can become @lquotes@;de-initialized@rquotes@; by being part of an @b(out) |
| 3548 |
parameter. |
| 3549 |
@end{Reason} |
| 3550 |
@begin{Ramification} |
| 3551 |
This includes an array type whose component type is an access type, |
| 3552 |
and a record type with a component that has a @nt{default_expression}, |
| 3553 |
among other things. |
| 3554 |
@end{Ramification} |
| 3555 |
|
| 3556 |
For any other type, the formal parameter is uninitialized. |
| 3557 |
If composite, a view conversion of the actual |
| 3558 |
parameter to the nominal subtype of the formal is evaluated |
| 3559 |
@Redundant[(which might raise Constraint_Error)], |
| 3560 |
and the actual subtype of the formal is that of the |
| 3561 |
view conversion. If elementary, the actual subtype of the formal |
| 3562 |
is given by its nominal subtype. |
| 3563 |
@begin{Ramification} |
| 3564 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0228-1]} |
| 3565 |
This case covers scalar types@Chg{Version=[3],New=[ that do not have |
| 3566 |
Default_Value specified],Old=[]}, and composite types whose |
| 3567 |
subcomponent's subtypes do not have any implicit initial values. |
| 3568 |
The view conversion for composite types ensures that if the lengths |
| 3569 |
don't match between an actual and a formal array parameter, |
| 3570 |
the Constraint_Error is raised before the call, rather than after. |
| 3571 |
@end{Ramification} |
| 3572 |
@end(itemize) |
| 3573 |
|
| 3574 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0142-4],ARef=[AI05-0234-1]} |
| 3575 |
@ChgAdded{Version=[3],Text=[In a function call, for each explicitly aliased |
| 3576 |
parameter, a check is made that the accessibility level of the master of the |
| 3577 |
actual object is not deeper than that of the master of the call |
| 3578 |
(see @RefSecNum{Operations of Access Types}).]} |
| 3579 |
@begin{Ramification} |
| 3580 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3581 |
@ChgAdded{Version=[3],Text=[If the actual object to a call @i<C> is a formal |
| 3582 |
parameter of some function call @i<F>, no dynamic check against the master of |
| 3583 |
the actual parameter of @i<F> is necessary. Any case which could fail the |
| 3584 |
dynamic check is already statically illegal (either at the call site of @i<F>, |
| 3585 |
or at the call site @i<C>). This is important, as it would require nasty |
| 3586 |
distributed overhead to accurately know the dynamic accessibility of a formal |
| 3587 |
parameter (all tagged and explicitly aliased parameters would have to carry |
| 3588 |
accessibility levels).]} |
| 3589 |
@end{Ramification} |
| 3590 |
@end{Itemize} |
| 3591 |
|
| 3592 |
@PDefn2{Term=[constrained],Sec=(object)} |
| 3593 |
@PDefn2{Term=[unconstrained],Sec=(object)} |
| 3594 |
A formal parameter of mode @key[in out] or @key[out] with |
| 3595 |
discriminants is constrained if either its nominal subtype |
| 3596 |
or the actual parameter is constrained. |
| 3597 |
|
| 3598 |
@Defn{parameter copy back} |
| 3599 |
@Defn{copy back of parameters} |
| 3600 |
@Defn{parameter assigning back} |
| 3601 |
@Defn{assigning back of parameters} |
| 3602 |
@Defn2{Term=[assignment operation], Sec=(during parameter copy back)} |
| 3603 |
After normal completion and leaving of a subprogram, for each @key(in out) |
| 3604 |
or @key(out) parameter that is passed by copy, |
| 3605 |
the value of the formal parameter is converted to |
| 3606 |
the subtype of the variable given as the actual parameter |
| 3607 |
and assigned to it. |
| 3608 |
@PDefn2{Term=[implicit subtype conversion],Sec=(parameter passing)} |
| 3609 |
These conversions and assignments occur in an arbitrary |
| 3610 |
order.@PDefn2{Term=[arbitrary order],Sec=[allowed]} |
| 3611 |
@begin{Ramification} |
| 3612 |
The conversions mentioned above during parameter passing might raise |
| 3613 |
Constraint_Error @em (see @RefSecNum{Type Conversions}). |
| 3614 |
@end{Ramification} |
| 3615 |
@begin{Ramification} |
| 3616 |
If any conversion or assignment as part of parameter passing |
| 3617 |
propagates an exception, the exception is raised at the place |
| 3618 |
of the subprogram call; |
| 3619 |
that is, it cannot be handled inside the @nt{subprogram_body}. |
| 3620 |
@end{Ramification} |
| 3621 |
@begin{TheProof} |
| 3622 |
Since these checks happen before or after executing the |
| 3623 |
@nt{subprogram_body}, the execution of the @nt{subprogram_body} does |
| 3624 |
not dynamically enclose them, so it can't handle the exceptions. |
| 3625 |
@end{TheProof} |
| 3626 |
@begin{Discussion} |
| 3627 |
The variable we're talking about is the one denoted by the |
| 3628 |
@i{variable_}@nt{name} given as the @nt{explicit_actual_parameter}. |
| 3629 |
If this @i{variable_}@nt{name} is a @nt{type_conversion}, |
| 3630 |
then the rules in @RefSecNum{Type Conversions} for assigning to a view |
| 3631 |
conversion apply. |
| 3632 |
That is, if X is of subtype S1, and the actual is S2(X), |
| 3633 |
the above-mentioned conversion will convert to S2, |
| 3634 |
and the one mentioned in @RefSecNum{Type Conversions} will convert to |
| 3635 |
S1. |
| 3636 |
@end{Discussion} |
| 3637 |
@end{RunTime} |
| 3638 |
|
| 3639 |
@begin{Erron} |
| 3640 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]} |
| 3641 |
@ChgAdded{Version=[3],Text=[@PDefn2{Term=(erroneous execution),Sec=(cause)}If |
| 3642 |
the nominal subtype of a formal parameter with discriminants is constrained or |
| 3643 |
indefinite, and the parameter is passed by reference, then the execution of the |
| 3644 |
call is erroneous if the value of any discriminant of the actual is changed |
| 3645 |
while the formal parameter exists (that is, before leaving the corresponding |
| 3646 |
callable construct).]} |
| 3647 |
@end{Erron} |
| 3648 |
|
| 3649 |
@begin{Extend83} |
| 3650 |
@Defn{extensions to Ada 83} |
| 3651 |
In Ada 95, a program can rely on the fact that passing an object as |
| 3652 |
an @key[out] parameter does not @lquotes@;de-initialize@rquotes@; any parts of the |
| 3653 |
object whose subtypes have implicit initial values. |
| 3654 |
(This generalizes the RM83 rule that required copy-in for parts that |
| 3655 |
were discriminants or of an access type.) |
| 3656 |
@end{Extend83} |
| 3657 |
|
| 3658 |
@begin{DiffWord83} |
| 3659 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 3660 |
We have eliminated the subclause on Default Parameters, |
| 3661 |
as it is subsumed by earlier @Chg{Version=[3],New=[],Old=[clauses and ]}subclauses. |
| 3662 |
@end{DiffWord83} |
| 3663 |
|
| 3664 |
@begin{Inconsistent2005} |
| 3665 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0196-1]} |
| 3666 |
@ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005} |
| 3667 |
@b<Correction:> Clarified that |
| 3668 |
@key[out] parameters of an access type are not checked for null exclusions |
| 3669 |
when they are passed in (which is similar to the behavior for constraints). |
| 3670 |
This was unspecified in Ada 2005, so a program which depends on the |
| 3671 |
behavior of an implementation which does check the exclusion may |
| 3672 |
malfunction. But a program depending on an exception being raised is unlikely.]} |
| 3673 |
@end{Inconsistent2005} |
| 3674 |
|
| 3675 |
@begin{Incompatible2005} |
| 3676 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0144-2]} |
| 3677 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005} |
| 3678 |
Additional rules have been added to make illegal passing the same elementary |
| 3679 |
object to more than one @key[in out] or @key[out] parameters of the same |
| 3680 |
call. In this case, the result in the object could depend on the compiler |
| 3681 |
version, optimization settings, and potentially the phase of the moon, so |
| 3682 |
this check will mostly reject programs that are nonportable and could |
| 3683 |
fail with any change. Even when the result is expected to be the same in both |
| 3684 |
parameters, the code is unnecessarily tricky. Programs which fail this |
| 3685 |
new check should be rare and are easily fixed by adding a temporary object.]} |
| 3686 |
@end{Incompatible2005} |
| 3687 |
|
| 3688 |
@begin{DiffWord2005} |
| 3689 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0008-1]} |
| 3690 |
@ChgAdded{Version=[3],Text=[@b<Correction:> A missing rule was |
| 3691 |
added to cover cases that were missed in Ada 95 and Ada 2005; specifically, |
| 3692 |
that an @key[in] parameter passed by reference might have its discriminants |
| 3693 |
changed via another path. Such cases are erroneous as requiring compilers |
| 3694 |
to detect such errors would be expensive, and requiring such cases to |
| 3695 |
work would be a major change of the user model (@key[in] parameters |
| 3696 |
with discriminants could no longer be assumed constant). This is not |
| 3697 |
an inconsistency, as compilers are not required to change any current |
| 3698 |
behavior.]} |
| 3699 |
|
| 3700 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0102-1]} |
| 3701 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Moved implicit conversion |
| 3702 |
@LegalityName to @RefSecNum{The Context of Overload Resolution}.]} |
| 3703 |
|
| 3704 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0118-1]} |
| 3705 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Added a definition for |
| 3706 |
positional parameters, as this is missing from Ada 95 and later.]} |
| 3707 |
|
| 3708 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0142-4]} |
| 3709 |
@ChgAdded{Version=[3],Text=[Rules have been added defining the legality |
| 3710 |
and dynamic checks needed for explicitly aliased parameters (see |
| 3711 |
@RefSecNum{Subprogram Declarations}).]} |
| 3712 |
|
| 3713 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0144-2]} |
| 3714 |
@ChgAdded{Version=[3],Text=[Additional rules have been added such |
| 3715 |
that passing an object to an @key[in out] |
| 3716 |
or @key[out] parameter of a function is illegal if it is used elsewhere in a |
| 3717 |
construct which allows evaluation in an arbitrary order. Such calls are |
| 3718 |
not portable (since the results may depend on the evaluation order), and |
| 3719 |
the results could even vary because of optimization settings and the like. |
| 3720 |
Thus they've been banned.]} |
| 3721 |
@end{DiffWord2005} |
| 3722 |
|
| 3723 |
@begin{Incompatible2012} |
| 3724 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0074-1],ARef=[AI12-0159-1]} |
| 3725 |
@ChgAdded{Version=[4],Text=[@Defn{incompatibilities with Ada 2005}@b<Corrigendum:> |
| 3726 |
Added rules to ensure that the value passed into a @key[out] parameter |
| 3727 |
for elementary types is well-defined in the case of a view conversion. |
| 3728 |
The new rules can be incompatible. For a view conversion to an unrelated type |
| 3729 |
with the Default_Value aspect specified, the aspect is new in Ada 2012 so it |
| 3730 |
should be unlikely to occur in existing code. For a view conversion to an |
| 3731 |
unrelated access type, the incompatibility is possible as this could be |
| 3732 |
written in Ada 95, but such a view conversion is thought to be rare. In both |
| 3733 |
cases, declaring and passing a temporary rather than a view conversion |
| 3734 |
will eliminate the problem.]} |
| 3735 |
|
| 3736 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0095-1]} |
| 3737 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Because of a rule added in |
| 3738 |
@RefSecNum{Formal Private and Derived Types}, the checks for the |
| 3739 |
passing of an object to an explicitly aliased parameter in a generic body |
| 3740 |
were strengthened to use an assume the worst rule. This case is rather |
| 3741 |
unlikely as a formal private or derived type with discriminants is required |
| 3742 |
along with an explicitly aliased parameter whose type doesn't statically |
| 3743 |
match the formal type. Such a program is very unlikely, especially as |
| 3744 |
explicitly aliased parameters are a new Ada 2012 feature.]} |
| 3745 |
@end{Incompatible2012} |
| 3746 |
|
| 3747 |
|
| 3748 |
|
| 3749 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 3750 |
@LabeledClause{Return Statements} |
| 3751 |
|
| 3752 |
@begin{Intro} |
| 3753 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3754 |
A @Chg{Version=[2],New=[@nt{simple_@!return_@!statement} or |
| 3755 |
@nt{extended_@!return_@!statement} (collectively called a @i<return statement>) |
| 3756 |
@Defn{return statement}],Old=[@nt{return_statement}]} is used to |
| 3757 |
complete the execution of the |
| 3758 |
innermost enclosing @nt{subprogram_@!body}, |
| 3759 |
@nt{entry_@!body}, or @nt{accept_@!statement}. |
| 3760 |
@end{Intro} |
| 3761 |
|
| 3762 |
@begin{Syntax} |
| 3763 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3764 |
@Syn{lhs=<@Chg{Version=[2],New=[simple_return_statement],Old=[return_statement]}>,rhs="@key{return} [@Syn2{expression}];"} |
| 3765 |
|
| 3766 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0277-1]} |
| 3767 |
@AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=[extended_return_object_declaration],Old=[]}>, |
| 3768 |
rhs="@Chg{Version=[3],New=< |
| 3769 |
@Syn2{defining_identifier} : [@key{aliased}][@key{constant}] @Syn2{return_subtype_indication} [:= @Syn2{expression}]>,Old=[]}"} |
| 3770 |
|
| 3771 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3772 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0015-1],ARef=[AI05-0053-1],ARef=[AI05-0277-1],ARef=[AI05-0299-1]} |
| 3773 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[extended_return_statement],Old=[]}>, |
| 3774 |
rhs="@Chg{Version=[2],New=< |
| 3775 |
@key{return} @Chg{Version=[3],New=<@Syn2{extended_return_object_declaration}>,Old=<@Syn2{defining_identifier} : [@Chg{Version=[3],New=<@Key{constant}>,Old=[@Key{aliased}]}] @Syn2{return_subtype_indication} [:= @Syn2{expression}]>} [@Key{do} |
| 3776 |
@Syn2{handled_sequence_of_statements} |
| 3777 |
@key{end} @key{return}];>,Old=[]}"} |
| 3778 |
|
| 3779 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3780 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=[return_subtype_indication],Old=[]}>, |
| 3781 |
rhs="@Chg{Version=[2],New=<@Syn2{subtype_indication} | @Syn2{access_definition}>,Old=[]}"} |
| 3782 |
|
| 3783 |
@end{Syntax} |
| 3784 |
|
| 3785 |
@begin{Resolution} |
| 3786 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3787 |
@Chg{Version=[2],New=[@Defn2{Term=[result subtype], Sec=(of a function)} |
| 3788 |
The @i<result subtype> of a function is the subtype denoted by the |
| 3789 |
@nt<subtype_mark>, or defined by the @nt<access_definition>, after the reserved |
| 3790 |
word @key<return> in the profile of the function.@PDefn2{Term=[expected type], |
| 3791 |
Sec=(@nt{expression} of @nt<simple_@!return_@!statement>)}],Old=[@Defn{return expression} |
| 3792 |
The @nt{expression}, if any, of a @nt{return_statement} is called the |
| 3793 |
@i{return expression}. |
| 3794 |
@Defn2{Term=[result subtype], Sec=(of a function)} |
| 3795 |
The @i(result subtype) of a function is the subtype denoted by the |
| 3796 |
@nt{subtype_mark} after the reserved word @key(return) in the profile |
| 3797 |
of the function.@PDefn2{Term=[expected type], Sec=(return expression)}]} |
| 3798 |
The expected type for @Chg{Version=[2],New=[the @nt{expression}, if any, of a |
| 3799 |
@nt{simple_@!return_@!statement}],Old=[a return expression]} is the result type of |
| 3800 |
the corresponding function.@Chg{Version=[2],New=[ |
| 3801 |
@PDefn2{Term=[expected type], Sec=(@nt{expression} of @nt{extended_return_statement})} |
| 3802 |
The expected type for the |
| 3803 |
@nt{expression} of an @nt{extended_return_statement} is that of the |
| 3804 |
@nt{return_@!subtype_@!indication}.],Old=[]} |
| 3805 |
@begin{Honest} |
| 3806 |
The same applies to generic functions. |
| 3807 |
@end{Honest} |
| 3808 |
@end{Resolution} |
| 3809 |
|
| 3810 |
@begin{Legality} |
| 3811 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3812 |
@Chg{Version=[2],New=[@Defn2{Term=[apply], |
| 3813 |
Sec=(to a callable construct by a return statement)}], |
| 3814 |
Old=[@Defn2{Term=[apply], Sec=(to a callable construct by a @nt{return_statement})}]} |
| 3815 |
A @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 3816 |
shall be within a callable construct, |
| 3817 |
and it @i{applies to} the innermost @Chg{Version=[2],New=[callable construct |
| 3818 |
or @nt{extended_return_statement} that contains it],Old=[one]}. |
| 3819 |
A @Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} shall |
| 3820 |
not be within a body that is within the construct to which the |
| 3821 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} applies. |
| 3822 |
|
| 3823 |
@begin{Honest} |
| 3824 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0089-1]} |
| 3825 |
@ChgAdded{Version=[4],Text=[The above also applies to generic subprograms, |
| 3826 |
even though they are not callable constructs. (An instance of a generic |
| 3827 |
subprogram is a callable construct, but not a generic subprogram itself.)]} |
| 3828 |
@end{Honest} |
| 3829 |
|
| 3830 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3831 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0015-1]} |
| 3832 |
A function body shall contain at least one |
| 3833 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} that |
| 3834 |
applies to the function body, |
| 3835 |
unless the function contains @nt{code_statement}s. |
| 3836 |
A @Chg{Version=[2],New=[@nt{simple_@!return_@!statement}],Old=[@nt{return_@!statement}]} shall |
| 3837 |
include @Chg{Version=[2],New=[an @nt{expression}],Old=[a return expression]} |
| 3838 |
if and only if it applies to a function |
| 3839 |
body.@Chg{Version=[2],New=[ An @nt<extended_return_statement> shall apply to |
| 3840 |
a function body.],Old=[]}@Chg{Version=[3],New=[ An @nt{extended_return_statement} |
| 3841 |
with the reserved word @key[constant] shall include an @nt{expression}.],Old=[]} |
| 3842 |
|
| 3843 |
@begin{Reason} |
| 3844 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 3845 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0022-1]} |
| 3846 |
The requirement that a function body has to have at least one |
| 3847 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]} |
| 3848 |
is a @lquotes@;helpful@rquotes@; restriction. |
| 3849 |
There @Chg{Version=[2],New=[has],Old=[was]} been some interest in lifting |
| 3850 |
this restriction, or allowing a raise statement to substitute for the |
| 3851 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_@!statement}]}. |
| 3852 |
However, there was enough interest in leaving it as is |
| 3853 |
that we decided not to change it.@Chg{Version=[4],New=[ Note that for |
| 3854 |
Ada 2012, Corrigendum 1, a return statement whose expression is a |
| 3855 |
@nt{raise_expression} can be given in @i<any> function body (the |
| 3856 |
@nt{raise_expression} will match any type), so there is |
| 3857 |
much less need to eliminate this rule.],Old=[]} |
| 3858 |
@end{Reason} |
| 3859 |
@begin{Ramification} |
| 3860 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 3861 |
@ChgAdded{Version=[2],Text=[A return statement can apply to an |
| 3862 |
@nt{extended_return_statement}, so a @nt{simple_@!return_@!statement} without |
| 3863 |
an @nt{expression} can be given in one. However, neither |
| 3864 |
@nt{simple_@!return_@!statement} with an @nt{expression} nor an |
| 3865 |
@nt{extended_return_statement} can be given inside an |
| 3866 |
@nt{extended_return_statement}, as they must apply (directly) to a |
| 3867 |
function body.]} |
| 3868 |
|
| 3869 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0089-1]} |
| 3870 |
@ChgAdded{Version=[4],Text=[Since a "function body" includes a generic |
| 3871 |
function body, this rule and all of the following @LegalityTitle apply |
| 3872 |
to generic function bodies as well as non-generic function bodies. This is |
| 3873 |
true even though a generic function is not a function.]} |
| 3874 |
@end{Ramification} |
| 3875 |
|
| 3876 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3877 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For an |
| 3878 |
@nt{extended_@!return_@!statement} that applies to a function body:]} |
| 3879 |
|
| 3880 |
@begin{Itemize} |
| 3881 |
|
| 3882 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3883 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1],ARef=[AI05-0103-1]} |
| 3884 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is defined by a |
| 3885 |
@nt{subtype_mark}, the @nt{return_@!subtype_@!indication} shall be a |
| 3886 |
@nt{subtype_indication}. The type of the @nt{subtype_indication} |
| 3887 |
shall be@Chg{Version=[3],New=[ covered by],Old=[]} the |
| 3888 |
result type of the function. @Chg{Version=[3],New=[The],Old=[If the result |
| 3889 |
subtype of the function is constrained, then the]} subtype defined by the |
| 3890 |
@nt{subtype_indication} shall @Chg{Version=[3],New=[be statically compatible |
| 3891 |
with the result subtype of the function; if the result type of the |
| 3892 |
function is elementary, the two subtypes],Old=[also |
| 3893 |
be constrained and]} shall statically match@Chg{Version=[3],New=[],Old=[ this |
| 3894 |
result subtype]}.@PDefn2{Term=[statically matching],Sec=(required)} |
| 3895 |
If the result subtype of the function is @Chg{Version=[3],New=[indefinite], |
| 3896 |
Old=[unconstrained]}, then the subtype |
| 3897 |
defined by the @nt{subtype_indication} shall be a definite subtype, or there |
| 3898 |
shall be an @nt{expression}.]} |
| 3899 |
|
| 3900 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3901 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is defined |
| 3902 |
by an @nt{access_definition}, the @nt{return_@!subtype_@!indication} shall be an |
| 3903 |
@nt{access_definition}. The subtype defined by the @nt{access_definition} shall |
| 3904 |
statically match the result subtype of the function. @Redundant[The accessibility |
| 3905 |
level of this anonymous access subtype is that of the result subtype.]]} |
| 3906 |
@begin{TheProof} |
| 3907 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0070-1]} |
| 3908 |
@ChgAdded{Version=[4],Text=[The accessibility of such anonymous access |
| 3909 |
types is defined in the Heart of Darkness (aka |
| 3910 |
@RefSecnum{Operations of Access Types}).]} |
| 3911 |
@end{TheProof} |
| 3912 |
|
| 3913 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0032-1]} |
| 3914 |
@ChgAdded{Version=[3],Text=[If the result subtype of the function is class-wide, |
| 3915 |
the accessibility level of the type of the subtype defined by the |
| 3916 |
@nt{return_subtype_indication} |
| 3917 |
shall not be statically deeper than that of the master that elaborated |
| 3918 |
the function body.]} |
| 3919 |
@begin{Reason} |
| 3920 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3921 |
@ChgAdded{Version=[3],Text=[In this case, the @nt{return_subtype_indication} |
| 3922 |
could be a specific type initialized by default; in that case there is no |
| 3923 |
@nt{expression} to check.]} |
| 3924 |
@end{Reason} |
| 3925 |
@end{Itemize} |
| 3926 |
|
| 3927 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3928 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1]}@Comment{Paragraph number only change} |
| 3929 |
@ChgAdded{Version=[2],Type=[Leading],Text=[For any return statement |
| 3930 |
that applies to a function body:]} |
| 3931 |
|
| 3932 |
@begin{Itemize} |
| 3933 |
|
| 3934 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 3935 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0188-1]}@Comment{Paragraph number only change} |
| 3936 |
@ChgAdded{Version=[2],Text=[@Redundant[If the result subtype of the function is limited, |
| 3937 |
then the @nt{expression} of the return statement (if any) shall @Chg{Version=[3], |
| 3938 |
New=[meet the restrictions described in @RefSecNum{Limited Types}],Old=[be an |
| 3939 |
@nt{aggregate}, a function call (or equivalent use of an operator), or a |
| 3940 |
@nt{qualified_expression} or parenthesized expression whose operand is one of |
| 3941 |
these]}.]]} |
| 3942 |
@begin{Discussion} |
| 3943 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3944 |
@ChgRef{Version=[3],Kind=[Deleted],ARef=[AI05-0188-1]} |
| 3945 |
@ChgDeleted{Version=[3],Text=[@Chg{Version=[2],New=[In other words, if limited, the @nt{expression} |
| 3946 |
must produce a @lquotes@;new@rquotes@; object, rather than being the name |
| 3947 |
of a preexisting object (which would imply copying).],Old=[]}]} |
| 3948 |
@end{Discussion} |
| 3949 |
|
| 3950 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00416-01]} |
| 3951 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1],ARef=[AI05-0051-1]} |
| 3952 |
@ChgAdded{Version=[2],Text=[If the result subtype of the function is class-wide, |
| 3953 |
the accessibility level of the type of the @nt{expression} |
| 3954 |
@Chg{Version=[3],New=[(if any) ],Old=[]}of the return |
| 3955 |
statement shall not be statically deeper than that of the master that |
| 3956 |
elaborated the function body.@Chg{Version=[3],New=[],Old=[ If the result subtype |
| 3957 |
has one or more |
| 3958 |
unconstrained access discriminants, the accessibility level of the anonymous |
| 3959 |
access type of each access discriminant, as determined by the |
| 3960 |
@nt{expression} of the @nt{simple_@!return_@!statement} or the |
| 3961 |
@nt{return_@!subtype_@!indication}, shall not be |
| 3962 |
statically deeper than that of the master that elaborated the function body.]}]} |
| 3963 |
|
| 3964 |
@begin{Discussion} |
| 3965 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 3966 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0032-1],ARef=[AI05-0051-1]} |
| 3967 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]} |
| 3968 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[If],Old=[We know that if]} |
| 3969 |
the result type is @Chg{Version=[4],New=[class-wide],Old=[class wide]}, |
| 3970 |
then there must be an @nt{expression} of the |
| 3971 |
return statement@Chg{Version=[3],New=[ unless this is |
| 3972 |
an @nt{extended_return_statement} whose @nt{return_subtype_indication} is |
| 3973 |
a specific type. We have a separate rule to cover that case. Note that |
| 3974 |
if an @nt{extended_return_statement} has an @nt{expression}, then both this |
| 3975 |
rule and the next one must be satisfied],Old=[. Similarly, if |
| 3976 |
the result subtype is unconstrained, then either the |
| 3977 |
@nt{return_@!subtype_@!indication} (if any) is constrained, or |
| 3978 |
there must be an @nt{expression}]}.]} |
| 3979 |
@end{Discussion} |
| 3980 |
|
| 3981 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0051-1]} |
| 3982 |
@ChgAdded{Version=[3],Text=[If the subtype determined by the @nt{expression} of the |
| 3983 |
@nt{simple_return_statement} or by the @nt{return_subtype_indication} has |
| 3984 |
one or more access discriminants, the accessibility level of the anonymous |
| 3985 |
access type of each access discriminant shall not be statically deeper than that |
| 3986 |
of the master that elaborated the function body.]} |
| 3987 |
|
| 3988 |
@begin{Discussion} |
| 3989 |
@ChgRef{Version=[3],Kind=[Added]} |
| 3990 |
@ChgAdded{Version=[3],Text=[We use the type used by the return statement |
| 3991 |
rather than from the function return type since we want to check whenever |
| 3992 |
the return object has access discriminants, even if the function return type |
| 3993 |
doesn't have any (mostly for a class-wide type).]} |
| 3994 |
@end{Discussion} |
| 3995 |
@end{Itemize} |
| 3996 |
|
| 3997 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0277-1]} |
| 3998 |
@ChgAdded{Version=[3],Text=[If the keyword @key[aliased] is present in an |
| 3999 |
@nt{extended_return_object_declaration}, |
| 4000 |
the type of the extended return object shall be immutably limited.]} |
| 4001 |
@end{Legality} |
| 4002 |
|
| 4003 |
@begin{StaticSem} |
| 4004 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02]} |
| 4005 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0015-1],ARef=[AI05-0144-2]} |
| 4006 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[return object], Sec=(extended_return_statement)} |
| 4007 |
Within an @nt{extended_return_statement}, the @i{return object} is declared |
| 4008 |
with the given @nt{defining_identifier}, with the nominal subtype defined by |
| 4009 |
the @nt{return_@!subtype_@!indication}.@Chg{Version=[3],New=[ An |
| 4010 |
@nt{extended_return_statement} with the reserved word @key[constant] |
| 4011 |
is a full constant declaration that declares the return object to be a |
| 4012 |
constant object.],Old=[]}]} |
| 4013 |
@end{StaticSem} |
| 4014 |
|
| 4015 |
@begin{RunTime} |
| 4016 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-00318-02],ARef=[AI95-00416-01]} |
| 4017 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0032-1]} |
| 4018 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[execution], Sec=(extended_return_statement)} |
| 4019 |
For the execution of an @nt{extended_return_statement}, the |
| 4020 |
@nt{subtype_indication} or @nt{access_definition} is elaborated. This creates |
| 4021 |
the nominal subtype of the return object. If there is an @nt{expression}, it |
| 4022 |
is evaluated and converted to the nominal subtype (which might raise |
| 4023 |
Constraint_Error @em see @RefSecNum{Type Conversions}@PDefn2{Term=[implicit subtype conversion],Sec=(function return)}); |
| 4024 |
the return object is created and the converted value is assigned to |
| 4025 |
the return object. Otherwise, the return object is created and initialized |
| 4026 |
by default as for a stand-alone object of its nominal subtype (see |
| 4027 |
@RefSecNum{Object Declarations}). If the nominal subtype is indefinite, the |
| 4028 |
return object is constrained by its initial |
| 4029 |
value.@PDefn2{Term=[creation],Sec=[of a return object]}@PDefn{constrained by its initial value}@Chg{Version=[3],New=[ |
| 4030 |
A check is made that the value of the return object belongs to the function |
| 4031 |
result subtype. Constraint_Error is raised if this |
| 4032 |
check fails.@Defn2{Term=[Constraint_Error], |
| 4033 |
Sec=(raised by failure of run-time check)} |
| 4034 |
@IndexCheck{Discriminant_Check}],Old=[]}]} |
| 4035 |
|
| 4036 |
@begin{Ramification} |
| 4037 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4038 |
@ChgAdded{Version=[2],Text=[If the result type is controlled or has a |
| 4039 |
controlled part, appropriate calls on Initialize or Adjust are performed |
| 4040 |
prior to executing the @nt{handled_sequence_of_statements}, except when the |
| 4041 |
initial expression is an @nt{aggregate} (which requires build-in-place |
| 4042 |
with no call on Adjust).]} |
| 4043 |
|
| 4044 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4045 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0005-1]} |
| 4046 |
@ChgAdded{Version=[2],Text=[If the return statement is left without resulting |
| 4047 |
in a return (for example, due to an exception propagated from the |
| 4048 |
@nt{expression} or the @nt{handled_sequence_of_statements}, or a goto out of |
| 4049 |
the @nt{handled_sequence_of_statements}), @Chg{Version=[3],New=[if ],Old=[]}the |
| 4050 |
return object @Chg{Version=[3],New=[has been created, it ],Old=[]}is |
| 4051 |
finalized prior to leaving the return statement.@Chg{Version=[3],New=[ If |
| 4052 |
it has not been created when the return statement is left, it is not |
| 4053 |
created or finalized.],Old=[]}]} |
| 4054 |
|
| 4055 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0032-1]} |
| 4056 |
@ChgAdded{Version=[3],Text=[Other rules ensure that the check required by |
| 4057 |
this rule cannot fail unless the function has a class-wide result subtype |
| 4058 |
where the associated specific subtype is constrained. In other cases, |
| 4059 |
either the subtypes have to match or the function's subtype is |
| 4060 |
unconstrained and needs no checking.]} |
| 4061 |
@end{Ramification} |
| 4062 |
|
| 4063 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4064 |
@Chg{Version=[2],New=[@PDefn2{Term=[execution], Sec=(simple_@!return_@!statement)}], |
| 4065 |
Old=[@PDefn2{Term=[execution], Sec=(return_statement)}]} |
| 4066 |
For the execution of a @Chg{Version=[2],New=[@nt{simple_@!return_@!statement}], |
| 4067 |
Old=[@nt{return_statement}]}, the @nt{expression} |
| 4068 |
(if any) is first evaluated@Chg{Version=[2],New=[,],Old=[ and]} converted to |
| 4069 |
the result subtype@Chg{Version=[2], |
| 4070 |
New=[, and then is assigned to the anonymous @i{return object}. |
| 4071 |
@PDefn2{Term=[return object], Sec=(simple_@!return_@!statement)}],Old=[.]} |
| 4072 |
@PDefn2{Term=[implicit subtype conversion],Sec=(function return)} |
| 4073 |
@begin{Ramification} |
| 4074 |
The conversion might raise |
| 4075 |
Constraint_Error @em (see @RefSecNum{Type Conversions}). |
| 4076 |
@end{Ramification} |
| 4077 |
|
| 4078 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00416-01]} |
| 4079 |
@Chg{Version=[2],New=[@Redundant[If the return object has any parts that are tasks, the |
| 4080 |
activation of those tasks does not occur until after the function returns (see |
| 4081 |
@RefSecNum{Task Execution - Task Activation}).]], |
| 4082 |
Old=[If the result type is class-wide, then |
| 4083 |
the tag of the result is the tag of the value |
| 4084 |
of the @nt<expression>.]} |
| 4085 |
@begin{TheProof} |
| 4086 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4087 |
@ChgAdded{Version=[2],Text=[This is specified by the rules in |
| 4088 |
@RefSecNum{Task Execution - Task Activation}.]} |
| 4089 |
@end{TheProof} |
| 4090 |
@begin{Reason} |
| 4091 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4092 |
@ChgAdded{Version=[2],Text=[Only the caller can know when task activations |
| 4093 |
should take place, as it depends on the context of the call. If the function |
| 4094 |
is being used to initialize the component of some larger object, then that |
| 4095 |
entire object must be initialized before any task activations. Even after the |
| 4096 |
outer object is fully initialized, task activations are still postponed until |
| 4097 |
the @key{begin} at the end of the declarative part if the function is being |
| 4098 |
used to initialize part of a declared object.]} |
| 4099 |
@end{Reason} |
| 4100 |
|
| 4101 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00344-01]} |
| 4102 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0024-1],ARef=[AI05-0032-1]} |
| 4103 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0097-1]} |
| 4104 |
@ChgDeleted{Version=[2],Type=[Leading],Keepnext=[T],Text=[]}@ChgNote{A dummy |
| 4105 |
ChgDeleted to get conditional "Leading".}If |
| 4106 |
the result type @Chg{Version=[2],New=[of a function ],Old=[]}is a specific |
| 4107 |
tagged type@Chg{Version=[2],New=[, the tag of the return object is that |
| 4108 |
of the result type. If the result type is class-wide, the tag of the |
| 4109 |
return object is that of @Chg{Version=[4],New=[the value of the @nt{expression}, |
| 4110 |
unless the return object is defined by |
| 4111 |
an @nt{extended_return_object_declaration} with a @nt{subtype_indication} that |
| 4112 |
is specific, in which case it is that of ],Old=[]}@Chg{Version=[3],New=[the |
| 4113 |
type of the @nt{subtype_indication}],Old=[]}@Chg{Version=[4],New=[], |
| 4114 |
Old=[@Chg{Version=[3],New=[ if it is |
| 4115 |
specific, or otherwise that of ],Old=[]}the |
| 4116 |
value of the @Chg{Version=[3],New=[@nt{expression}],Old=[expression]}]}. |
| 4117 |
A check is made that |
| 4118 |
the @Chg{Version=[3],New=[master],Old=[accessibility level]} of the type |
| 4119 |
identified by the tag of the result @Chg{Version=[3],New=[includes the |
| 4120 |
elaboration],Old=[is not deeper than that]} of the master that elaborated |
| 4121 |
the function body. If |
| 4122 |
this check fails, Program_Error is raised.@Defn2{Term=[Program_Error], |
| 4123 |
Sec=(raised by failure of run-time check)} |
| 4124 |
@IndexCheck{Accessibility_Check}],Old=[:]} |
| 4125 |
|
| 4126 |
@begin{Ramification} |
| 4127 |
@ChgNote{Moved from after paragraph 10} |
| 4128 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4129 |
@ChgAdded{Version=[2],Text=[The first sentence is true even if the |
| 4130 |
tag of the @nt{expression} is different, which |
| 4131 |
could happen if the @nt{expression} were a view conversion or a |
| 4132 |
dereference of an access value. Note that for a limited type, because |
| 4133 |
of the restriction to @nt{aggregate}s and function calls (and no conversions), |
| 4134 |
the tag will already match]}. |
| 4135 |
@end{Ramification} |
| 4136 |
@begin{Reason} |
| 4137 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4138 |
@ChgAdded{Version=[2],Text=[The first rule ensures |
| 4139 |
that a function whose result type is |
| 4140 |
a specific tagged type always returns an object whose tag is that of the |
| 4141 |
result type. This is important for dispatching on controlling result, and |
| 4142 |
allows the caller to allocate the appropriate amount of space to hold |
| 4143 |
the value being returned (assuming there are no discriminants).]} |
| 4144 |
|
| 4145 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4146 |
@ChgRef{Version=[3],Kind=[Revised]} |
| 4147 |
@ChgAdded{Version=[2],Text=[The @Chg{Version=[3],New=[master ],Old=[]}check |
| 4148 |
prevents the returned object |
| 4149 |
from outliving its type. Note that this check cannot fail for a specific |
| 4150 |
tagged type, as the tag represents the function's type, which necessarily |
| 4151 |
must be declared outside of the function.]} |
| 4152 |
|
| 4153 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4154 |
@ChgAdded{Version=[3],Text=[We can't use the normal accessibility level |
| 4155 |
@lquotes@;deeper than@rquotes@; check |
| 4156 |
here because we may have @lquotes@;incomparable@rquotes@; levels if |
| 4157 |
the masters belong to two different tasks. This can happen when an |
| 4158 |
accept statement calls a function declared in the enclosing task body, and |
| 4159 |
the function returns an object passed to it from the accept statement, and |
| 4160 |
this object was itself a parameter to the accept statement.]} |
| 4161 |
@end{Reason} |
| 4162 |
@begin{Honest} |
| 4163 |
@ChgRef{Version=[4],Kind=[Added],ARef=[AI12-0097-1]} |
| 4164 |
@ChgAdded{Version=[4],Text=[The @nt{expression} here is the return expression |
| 4165 |
if the return statement is a @nt{simple_return_statement}, and the |
| 4166 |
initializing expression of the @nt{extended_return_object_declaration} if the |
| 4167 |
return statement is an @nt{extended_return_statement} (ignoring any inner |
| 4168 |
@nt{simple_return_statement}s, which necessarily cannot have an |
| 4169 |
@nt{expression}, and any other @nt{expression}s inside of the |
| 4170 |
@nt{extended_return_statement}).]} |
| 4171 |
@end{Honest} |
| 4172 |
|
| 4173 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0073-1]} |
| 4174 |
@ChgAdded{Version=[3],Text=[@IndexCheck{Tag_Check}If the result subtype |
| 4175 |
of the function is defined by |
| 4176 |
an @nt{access_definition} designating a specific tagged type @i<T>, a check |
| 4177 |
is made that the result value is null or the tag of the object designated |
| 4178 |
by the result value identifies @i<T>. |
| 4179 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 4180 |
Constraint_Error is raised if this check fails.]} |
| 4181 |
@begin{Reason} |
| 4182 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4183 |
@ChgAdded{Version=[3],Text=[This check is needed so that dispatching |
| 4184 |
on controlling access results works for tag-indeterminate functions. |
| 4185 |
If it was not made, it would be possible for such functions to return |
| 4186 |
an access to a descendant type, meaning the function could return |
| 4187 |
an object with a tag different than the one assumed by the |
| 4188 |
dispatching rules.]} |
| 4189 |
@end{Reason} |
| 4190 |
|
| 4191 |
@begin{NotIso} |
| 4192 |
@ChgAdded{Version=[2],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 9 |
| 4193 |
through 20 were deleted.>}]}@Comment{This message should be deleted if the |
| 4194 |
paragraphs are ever renumbered.} |
| 4195 |
@end{NotIso} |
| 4196 |
|
| 4197 |
@begin(itemize) |
| 4198 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4199 |
@ChgDeleted{Version=[2],Text=[@IndexCheck{Tag_Check} |
| 4200 |
If it is limited, then |
| 4201 |
a check is made that the tag of the value of the return expression |
| 4202 |
identifies the result type. |
| 4203 |
@Defn2{Term=[Constraint_Error],Sec=(raised by failure of run-time check)} |
| 4204 |
Constraint_Error is raised if this check fails.]} |
| 4205 |
|
| 4206 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4207 |
@ChgDeleted{Version=[2],Text=[If it is nonlimited, then |
| 4208 |
the tag of the result is that of the result type.]} |
| 4209 |
@begin{Ramification} |
| 4210 |
@ChgNote{These two notes were revised and moved up} |
| 4211 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4212 |
@ChgDeleted{Version=[2],Text=[This is true even if the |
| 4213 |
tag of the return expression is different.]} |
| 4214 |
@end{Ramification} |
| 4215 |
@begin{Reason} |
| 4216 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4217 |
@ChgDeleted{Version=[2],Text=[These rules ensure |
| 4218 |
that a function whose result type is |
| 4219 |
a specific tagged type always returns an object whose tag is that of the |
| 4220 |
result type. This is important for dispatching on controlling result, |
| 4221 |
and, if nonlimited, |
| 4222 |
allows the caller to allocate the appropriate amount of space to hold |
| 4223 |
the value being returned (assuming there are no discriminants).]} |
| 4224 |
@end{Reason} |
| 4225 |
@end(itemize) |
| 4226 |
|
| 4227 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4228 |
@ChgDeleted{Version=[2],Type=[Leading],Keepnext=[T], |
| 4229 |
Text=[@Defn{return-by-reference type} |
| 4230 |
A type is a @i(return-by-reference) type if it |
| 4231 |
is a descendant of one of the following:]} |
| 4232 |
@begin(itemize) |
| 4233 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4234 |
@ChgDeleted{Version=[2],Text=[a tagged limited type;]} |
| 4235 |
|
| 4236 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4237 |
@ChgDeleted{Version=[2],Text=[a task or protected type;]} |
| 4238 |
|
| 4239 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4240 |
@ChgDeleted{Version=[2],Text=[a nonprivate type with the reserved word |
| 4241 |
@b(limited) in its declaration;]} |
| 4242 |
|
| 4243 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4244 |
@ChgDeleted{Version=[2],Text=[a composite type with a subcomponent |
| 4245 |
of a return-by-reference type;]} |
| 4246 |
|
| 4247 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4248 |
@ChgDeleted{Version=[2],Text=[a private type |
| 4249 |
whose full type is a return-by-reference type.]} |
| 4250 |
@end(itemize) |
| 4251 |
@begin{Ramification} |
| 4252 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 4253 |
@ChgDeleted{Version=[2],Text=[ |
| 4254 |
The above rules are such that there are no "Ada 83" types other than |
| 4255 |
those containing tasks that are return-by-reference. This helps |
| 4256 |
to minimize upward incompatibilities relating to return-by-reference.]} |
| 4257 |
@end{Ramification} |
| 4258 |
|
| 4259 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4260 |
@ChgDeleted{Version=[2],Type=[Leading],Text=[@IndexCheck{Accessibility_Check} |
| 4261 |
If the result type is a return-by-reference type, |
| 4262 |
then a check is made that the return expression is one of the |
| 4263 |
following:]} |
| 4264 |
@begin(itemize) |
| 4265 |
|
| 4266 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4267 |
@ChgDeleted{Version=[2],Text=[a @nt{name} that denotes an object view |
| 4268 |
whose accessibility level is not deeper than that of the master that |
| 4269 |
elaborated the function body; or]} |
| 4270 |
@begin{Discussion} |
| 4271 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00316-01]} |
| 4272 |
@ChgNote{This really wasn't in the previous version, but we don't want it |
| 4273 |
in a version without deletions shown...} |
| 4274 |
@ChgDeleted{Version=[2],Text=[This rule was unnecessarily confusing, and the |
| 4275 |
parenthetical remark "(or a value with an associated object, see 6.2)" |
| 4276 |
was added @em and then the entire concept was deleted.]} |
| 4277 |
@end{Discussion} |
| 4278 |
|
| 4279 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4280 |
@ChgDeleted{Version=[2],Text=[a parenthesized expression or |
| 4281 |
@nt{qualified_expression} whose operand is one of these kinds of expressions.]} |
| 4282 |
|
| 4283 |
@end(itemize) |
| 4284 |
|
| 4285 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg],ARef=[AI95-00318-02]} |
| 4286 |
@ChgDeleted{Version=[2],Text=[@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 4287 |
The exception Program_Error is raised if this check fails.]} |
| 4288 |
@begin{Discussion} |
| 4289 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 4290 |
@ChgDeleted{Version=[2],Text=[Compare the definition of return-by-reference |
| 4291 |
with that of by-reference.]} |
| 4292 |
|
| 4293 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 4294 |
@ChgDeleted{Version=[2],Text=[The return-by-reference types are all limited types |
| 4295 |
except those that are limited only because of a limited |
| 4296 |
private type with a nonlimited untagged full type.]} |
| 4297 |
@end{Discussion} |
| 4298 |
@begin{Reason} |
| 4299 |
@ChgRef{Version=[2],Kind=[DeletedNoDelMsg]} |
| 4300 |
@ChgDeleted{Version=[2],Text=[@PDefn{generic contract issue} |
| 4301 |
This check can often be performed at compile time. It is |
| 4302 |
defined to be a run-time check to avoid generic contract model |
| 4303 |
problems. In a future version of the standard, we anticipate |
| 4304 |
that function return of a local variable will be illegal for all |
| 4305 |
limited types, eliminating the need for the run-time check |
| 4306 |
except for dereferences of an access parameter.]} |
| 4307 |
@end{Reason} |
| 4308 |
|
| 4309 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02],ARef=[AI95-00402-01],ARef=[AI95-00416-01]} |
| 4310 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0051-1]} |
| 4311 |
@Chg{Version=[2], |
| 4312 |
New=[If @Chg{Version=[3],New=[any part of the specific type of the return object], |
| 4313 |
Old=[the result subtype]} of a function |
| 4314 |
@Chg{Version=[3],New=[(or coextension thereof) ],Old=[]}has one or more |
| 4315 |
@Chg{Version=[3],New=[],Old=[unconstrained ]}access |
| 4316 |
discriminants@Chg{Version=[3],New=[ whose value is not constrained by the |
| 4317 |
result subtype of the function],Old=[]}, |
| 4318 |
a check is made that the accessibility level of the anonymous access type |
| 4319 |
of each access discriminant, as determined by the @nt{expression} or the |
| 4320 |
@nt{return_@!subtype_@!indication} of the @Chg{Version=[3],New=[return |
| 4321 |
statement],Old=[function]}, |
| 4322 |
is not deeper than @Chg{Version=[3],New=[the level of the master of the call |
| 4323 |
(see @RefSecNum{Operations of Access Types})], |
| 4324 |
Old=[that of the master that elaborated the |
| 4325 |
function body]}. If this check fails, Program_Error is raised. |
| 4326 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)} |
| 4327 |
@IndexCheck{Accessibility_Check}], |
| 4328 |
Old=[For a function with a return-by-reference result type |
| 4329 |
the result is returned by reference; |
| 4330 |
that is, the function call denotes a constant view of the |
| 4331 |
object associated |
| 4332 |
with the value of the return expression. |
| 4333 |
@Defn2{Term=[assignment operation], Sec=(during execution of a |
| 4334 |
@nt{return_statement})} |
| 4335 |
For any other function, the result is returned by copy; |
| 4336 |
that is, |
| 4337 |
the converted value is assigned into an anonymous constant created at |
| 4338 |
the point of the @nt{return_statement}, and the function call denotes |
| 4339 |
that object.]} |
| 4340 |
@begin{Ramification} |
| 4341 |
@ChgRef{Version=[2],Kind=[Deleted]} |
| 4342 |
@ChgDeleted{Version=[2],Text=[The assignment operation does the necessary |
| 4343 |
value adjustment, as described in |
| 4344 |
@RefSec{Assignment and Finalization}. |
| 4345 |
@RefSecNum{Completion and Finalization} |
| 4346 |
describes when the anonymous constant is finalized.]} |
| 4347 |
@end{Ramification} |
| 4348 |
@begin{Reason} |
| 4349 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4350 |
@ChgAdded{Version=[2],Text=[The check prevents the returned |
| 4351 |
object (for a nonlimited type) from outliving the object designated by one |
| 4352 |
of its discriminants. The check is made on the values of the discriminants, |
| 4353 |
which may come from the @nt{return_@!subtype_@!indication} (if constrained), |
| 4354 |
or the @nt{expression}, but it is never necessary to check both.]} |
| 4355 |
@end{Reason} |
| 4356 |
@begin{ImplNote} |
| 4357 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]} |
| 4358 |
@ChgAdded{Version=[3],Text=[The reason for saying @ldquote@;any part of |
| 4359 |
the specific type@rdquote is to simplify implementation. In the case of |
| 4360 |
class-wide result objects, this allows the testing of a simple flag in the |
| 4361 |
tagged type descriptor that indicates whether the specific type has any parts with |
| 4362 |
access discriminants. By basing the test on the type of the object rather than |
| 4363 |
the object itself, we avoid concerns about whether subcomponents in variant |
| 4364 |
parts and of arrays (which might be empty) are present.]} |
| 4365 |
@end{ImplNote} |
| 4366 |
@begin{Discussion} |
| 4367 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]} |
| 4368 |
@ChgAdded{Version=[3],Text=[For a function with a class-wide result type, the |
| 4369 |
access values that need to be checked are determined by the tag of the return |
| 4370 |
object. In order to implement this accessibility check in the case where the |
| 4371 |
tag of the result is not known statically at the point of the return |
| 4372 |
statement, an implementation may need to somehow associate with the tag of a |
| 4373 |
specific tagged type an indication of whether the type has unconstrained |
| 4374 |
access discriminants (explicit or inherited) or has any subcomponents with |
| 4375 |
such discriminants. If an implementation is already maintaining a statically |
| 4376 |
initialized descriptor of some kind for each specific tagged type, then an |
| 4377 |
additional Boolean could be added to this descriptor.]} |
| 4378 |
|
| 4379 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1],ARef=[AI05-0234-1]} |
| 4380 |
@ChgAdded{Version=[3],Text=[Note that the flag should only be queried in the |
| 4381 |
case where the result object might have access discriminants that might |
| 4382 |
have subtypes with "bad" accessibility levels (as determined by the rules of |
| 4383 |
@RefSecNum{Operations of Access Types} for determining the accessibility |
| 4384 |
level of the type of an access discriminant in the @nt{expression} or |
| 4385 |
@nt{return_subtype_indication} of a return statement).]} |
| 4386 |
|
| 4387 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4388 |
@ChgAdded{Version=[3],Type=[Leading],Text=[Thus, in a case like]} |
| 4389 |
|
| 4390 |
@begin{Example} |
| 4391 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4392 |
@ChgAdded{Version=[3],Text=[@key[type] Global @key[is access] T'Class; |
| 4393 |
@key[function] F (Ptr : Global) @key[return] T'Class @key[is] |
| 4394 |
@key[begin] |
| 4395 |
@key[return] Ptr.@key[all]; |
| 4396 |
@key[end] F;]} |
| 4397 |
@end{Example} |
| 4398 |
|
| 4399 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4400 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[there is no need for a run-time |
| 4401 |
accessibility check. While an object of T'Class "might have" access |
| 4402 |
discriminants, the accessibility of those potential discriminants |
| 4403 |
cannot be bad. The setting of the bit doesn't matter and there is no |
| 4404 |
need to query it.]} |
| 4405 |
|
| 4406 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4407 |
@ChgAdded{Version=[3],Type=[Leading],Text=[On the other hand, given]} |
| 4408 |
@begin{Example} |
| 4409 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4410 |
@ChgAdded{Version=[3],Text=[@key[function] F @key[return] T'Class @key[is] |
| 4411 |
Local : T'Class := ... ; |
| 4412 |
@key[begin] |
| 4413 |
@key[return] Local; |
| 4414 |
@key[end] F;]} |
| 4415 |
@end{Example} |
| 4416 |
|
| 4417 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4418 |
@ChgAdded{Version=[3],Type=[Trailing],Text=[In this case, a check would |
| 4419 |
typically be required.]} |
| 4420 |
|
| 4421 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4422 |
@ChgAdded{Version=[3],Type=[Leading],Text=[The need for including |
| 4423 |
subcomponents in this check is illustrated by the following example:]} |
| 4424 |
@begin{Example} |
| 4425 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4426 |
@ChgAdded{Version=[3],Text=[X : @key[aliased] Integer;]} |
| 4427 |
|
| 4428 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4429 |
@ChgAdded{Version=[3],Text=[@key[type] Component_Type (Discrim : @key[access] Integer := X'Access) |
| 4430 |
@key[is limited null record];]} |
| 4431 |
|
| 4432 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4433 |
@ChgAdded{Version=[3],Text=[@key[type] Undiscriminated @key[is record] |
| 4434 |
Fld : Component_Type; |
| 4435 |
@key[end record];]} |
| 4436 |
|
| 4437 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 4438 |
@ChgAdded{Version=[3],Text=[@key[function] F @key[return] Undiscriminated @key[is] |
| 4439 |
Local : @key[aliased] Integer; |
| 4440 |
@key[begin] |
| 4441 |
@key[return] X : Undiscriminated := (Fld => (Discrim => Local'Access)) @key[do] |
| 4442 |
Foo; |
| 4443 |
@key[end return]; |
| 4444 |
--@Examcom{ raises Program_Error after calling Foo.} |
| 4445 |
@key[end] F;]} |
| 4446 |
@end{Example} |
| 4447 |
@end{Discussion} |
| 4448 |
@begin{Ramification} |
| 4449 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0234-1]} |
| 4450 |
@ChgAdded{Version=[3],Text=[In the case where the tag of the result is not |
| 4451 |
known statically at the point of the return statement and the run-time |
| 4452 |
accessibility check is needed, discriminant values and array bounds play no |
| 4453 |
role in performing this check. That is, array components are assumed to have |
| 4454 |
nonzero length and components declared within variant parts are assumed to be |
| 4455 |
present. Thus, the check may be implemented simply by testing the |
| 4456 |
aforementioned descriptor bit and conditionally raising Program_Error.]} |
| 4457 |
@end{Ramification} |
| 4458 |
|
| 4459 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4460 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0058-1]} |
| 4461 |
@Chg{Version=[2],New=[For the execution of an |
| 4462 |
@nt{extended_@!return_@!statement}, the |
| 4463 |
@nt{handled_@!sequence_@!of_@!statements} is executed. Within this |
| 4464 |
@nt{handled_@!sequence_@!of_@!statements}, the execution of a |
| 4465 |
@nt{simple_@!return_@!statement} that applies to the |
| 4466 |
@nt{extended_@!return_@!statement} causes a transfer of control that completes |
| 4467 |
the @nt{extended_@!return_@!statement}. Upon completion |
| 4468 |
of a return statement that applies to a callable construct@Chg{Version=[3], |
| 4469 |
New=[ by the normal completion of a @nt{simple_@!return_@!statement} or |
| 4470 |
by reaching the @key[end return] of an @nt{extended_@!return_@!statement}], |
| 4471 |
Old=[]}],Old=[Finally]}, a |
| 4472 |
transfer of control is performed which completes the execution of the callable |
| 4473 |
construct@Chg{Version=[2],New=[], Old=[ to which the @nt{return_@!statement} |
| 4474 |
applies]}, and returns to the caller. |
| 4475 |
|
| 4476 |
@begin{Ramification} |
| 4477 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0058-1]} |
| 4478 |
@ChgAdded{Version=[3],Text=[A transfer of control that completes an |
| 4479 |
@nt{extended_return_statement} (such as an exit or goto) does not cause |
| 4480 |
a return to the caller unless it is caused by @nt{simple_return_statement} |
| 4481 |
(that is, triggers the second sentence of this paragraph). The return to |
| 4482 |
the caller occurs for the @nt{simple_return_statement} that applies to an |
| 4483 |
@nt{extended_return_statement} because the last sentence says |
| 4484 |
@ldquote@;the normal completion of a @nt{simple_return_statement}@rdquote@;, |
| 4485 |
which includes the one nested in the @nt{extended_return_statement}.]} |
| 4486 |
@end{Ramification} |
| 4487 |
|
| 4488 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4489 |
@ChgAdded{Version=[2],Text=[In the case of a function, the @nt{function_call} |
| 4490 |
denotes a constant view of the return object.]} |
| 4491 |
@end{RunTime} |
| 4492 |
|
| 4493 |
@begin{ImplPerm} |
| 4494 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 4495 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0050-1]} |
| 4496 |
@ChgAdded{Version=[3],Type=[Leading],Text=[]}@Comment{This is a fake used to provide a conditional leading.} |
| 4497 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[For a function call used to |
| 4498 |
initialize a composite],Old=[If the result subtype of a function is |
| 4499 |
unconstrained, and a call on the function is used to provide the initial value |
| 4500 |
of an]} object with a constrained nominal subtype@Chg{Version=[3],New=[ or |
| 4501 |
used to initialize a return object that is built in place |
| 4502 |
into such an object:],Old=[, Constraint_Error may be raised |
| 4503 |
at the point of the call (after abandoning the execution of the function body) |
| 4504 |
if, while elaborating the @nt{return_@!subtype_@!indication} or |
| 4505 |
evaluating the @nt{expression} of a return statement that applies to the |
| 4506 |
function body, it |
| 4507 |
is determined that the value of the result will violate the constraint of the |
| 4508 |
subtype of this object.]}]} |
| 4509 |
|
| 4510 |
@begin{Itemize} |
| 4511 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0050-1]} |
| 4512 |
@ChgAdded{Version=[3],Text=[If the result subtype of the function is |
| 4513 |
constrained, and conversion of an object of this subtype to the subtype of the |
| 4514 |
object being initialized would raise Constraint_Error, then Constraint_Error |
| 4515 |
may be raised before calling the function.]} |
| 4516 |
|
| 4517 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0050-1]} |
| 4518 |
@ChgAdded{Version=[3],Text=[If the result subtype of the function is |
| 4519 |
unconstrained, and a return statement is executed such that the return object |
| 4520 |
is known to be constrained, and conversion of the return object to the subtype |
| 4521 |
of the object being initialized would raise Constraint_Error, then |
| 4522 |
Constraint_Error may be raised at the point of the call (after abandoning the |
| 4523 |
execution of the function body).]} |
| 4524 |
@end{Itemize} |
| 4525 |
|
| 4526 |
@begin{Reason} |
| 4527 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 4528 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0050-1]} |
| 4529 |
@ChgAdded{Version=[2],Text=[Without such a permission, it would be very |
| 4530 |
difficult to implement |
| 4531 |
@lquotes@;@Chg{Version=[3],New=[built-in-place],Old=[build-in-place]}@rquotes semantics. |
| 4532 |
@Chg{Version=[3],New=[The intention is that the exception is raised at the |
| 4533 |
same point that it would have been raised without the permission; it |
| 4534 |
should not change handlers if the implementation switches between |
| 4535 |
return-by-copy and built-in-place. This means that the],Old=[Such an]} |
| 4536 |
exception is not handleable within the function, because in the |
| 4537 |
return-by-copy case, the constraint check to verify that the result satisfies |
| 4538 |
the constraints of the object being initialized happens after the function |
| 4539 |
returns@Chg{Version=[3],New=[],Old=[, and we want the semantics to change as |
| 4540 |
little as possible when switching between return-by-copy and build-in-place]}. |
| 4541 |
This implies further that upon detecting such a situation, the implementation |
| 4542 |
may need to simulate a goto to a point outside any local exception handlers |
| 4543 |
prior to raising the exception.]} |
| 4544 |
@end{Reason} |
| 4545 |
|
| 4546 |
@begin{Ramification} |
| 4547 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00416-01]} |
| 4548 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0050-1]} |
| 4549 |
@Chg{Version=[3],New=[These permissions do not apply in the case of an extended |
| 4550 |
return object with mutable discriminants. That's necessary because in that |
| 4551 |
case a return object can be created with the @ldquote@;wrong@rdquote |
| 4552 |
discriminants and then changed to the @ldquote@;right@rdquote discriminants |
| 4553 |
later (but before returning). We don't want this case raising an exception |
| 4554 |
when the canonical semantics will not do so.],Old=[@Chg{Version=[2],New=[This |
| 4555 |
permission is allowed during the evaluation of the @nt{expression} of an |
| 4556 |
@nt{extended_return_statement}, because the @nt{return_@!subtype_@!indication} |
| 4557 |
may be unconstrained and the @nt{expression} then would provide the |
| 4558 |
constraints.],Old=[]}]} |
| 4559 |
|
| 4560 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 4561 |
@ChgAdded{Version=[3],Text=[It's still possible to write a program that will |
| 4562 |
raise an exception using this permission that would not in the canonical |
| 4563 |
semantics. That could happen if a return statement with the |
| 4564 |
@ldquote@;wrong@rdquote discriminants or bounds is abandoned (via an |
| 4565 |
exception, or for an extended_return_statement, via an exit or goto |
| 4566 |
statement), and then a return statement with the @ldquote@;right@rdquote |
| 4567 |
discriminants or bounds is executed. The only solution for this problem is to |
| 4568 |
not have the permission at all, but this is too unusual of a case to worry about |
| 4569 |
the effects of the permission, especially given the implementation |
| 4570 |
difficulties for built-in-place objects that this permission is intended to |
| 4571 |
ease.]} |
| 4572 |
|
| 4573 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 4574 |
@ChgAdded{Version=[3],Text=[Note that the mutable-discriminant case only |
| 4575 |
happens when built-in-place initialization is optional. This means that any |
| 4576 |
difficulties associated with implementing built-in-place initialization |
| 4577 |
without these permissions can be sidestepped by not building in place.]} |
| 4578 |
|
| 4579 |
@end{Ramification} |
| 4580 |
|
| 4581 |
@end{ImplPerm} |
| 4582 |
|
| 4583 |
@begin{Examples} |
| 4584 |
@leading@keepnext@i{Examples of return statements:} |
| 4585 |
@begin{Example} |
| 4586 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4587 |
@key[return]; --@ExamCom{ in a procedure body, }@nt{entry_body}@ExamCom{,}@Chg{Version=[2],New=[ |
| 4588 |
-- @nt{accept_statement}@ExamCom{, or }@nt{extended_return_statement}],Old=[@ExamCom{ or }@nt{accept_statement}]} |
| 4589 |
|
| 4590 |
@key[return] Key_Value(Last_Index); --@ExamCom{ in a function body} |
| 4591 |
|
| 4592 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4593 |
@Chg{Version=[2],New=<@key[return] Node : Cell @key{do} --@ExamCom{ in a function body, see @RefSecNum{Incomplete Type Declarations} for Cell} |
| 4594 |
Node.Value := Result; |
| 4595 |
Node.Succ := Next_Node; |
| 4596 |
@key{end} @key{return};>,Old=<>} |
| 4597 |
@end{Example} |
| 4598 |
@end{Examples} |
| 4599 |
|
| 4600 |
@begin{Incompatible83} |
| 4601 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4602 |
@Defn{incompatibilities with Ada 83} |
| 4603 |
In Ada 95, if the result type of a function has a part that is a task, |
| 4604 |
then an attempt to return a local variable will raise Program_Error. |
| 4605 |
@Chg{Version=[2],New=[This is illegal in Ada 2005, see below. ], |
| 4606 |
Old=[]}In Ada 83, if a function returns a local variable containing a task, |
| 4607 |
execution is erroneous according to AI83-00867. However, |
| 4608 |
there are other situations where functions that return tasks |
| 4609 |
(or that return a variant record only one of whose variants |
| 4610 |
includes a task) |
| 4611 |
are correct in Ada 83 but will raise Program_Error according |
| 4612 |
to the new rules. |
| 4613 |
|
| 4614 |
The rule change was made because there will be more types (protected types, |
| 4615 |
limited controlled types) in Ada 95 for which |
| 4616 |
it will be meaningless to return a local variable, and making |
| 4617 |
all of these erroneous is unacceptable. |
| 4618 |
The current rule was felt to be the simplest that kept |
| 4619 |
upward incompatibilities to situations involving returning tasks, |
| 4620 |
which are quite rare. |
| 4621 |
@end{Incompatible83} |
| 4622 |
|
| 4623 |
@begin{DiffWord83} |
| 4624 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 4625 |
This @Chg{Version=[3],New=[subclause],Old=[clause]} has been moved here from |
| 4626 |
chapter 5, since it has mainly to do with subprograms. |
| 4627 |
|
| 4628 |
A function now creates an anonymous object. |
| 4629 |
This is necessary so that controlled types |
| 4630 |
will work. |
| 4631 |
|
| 4632 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4633 |
We have clarified that a |
| 4634 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]} |
| 4635 |
applies to a callable construct, not to a callable entity. |
| 4636 |
|
| 4637 |
@ChgRef{Version=[2],Kind=[Revised],ARef=[AI95-00318-02]} |
| 4638 |
There is no need to mention generics in the rules about where a |
| 4639 |
@Chg{Version=[2],New=[return statement],Old=[@nt{return_statement}]} |
| 4640 |
can appear and what it applies to; |
| 4641 |
the phrase @lquotes@;body of a subprogram or generic subprogram@rquotes@; is |
| 4642 |
syntactic, and refers exactly to @lquotes@;@nt{subprogram_body}@rquotes@;. |
| 4643 |
@end{DiffWord83} |
| 4644 |
|
| 4645 |
@begin{Inconsistent95} |
| 4646 |
@ChgRef{Version=[2],Kind=[Added],ARef=[AI95-0416-1]} |
| 4647 |
@ChgRef{Version=[3],Kind=[RevisedAdded],ARef=[AI05-0005-1],ARef=[AI05-0050-1]} |
| 4648 |
@ChgAdded{Version=[2],Text=[@Defn{inconsistencies with Ada 95} |
| 4649 |
Added an @ImplPermName allowing early raising of Constraint_Error if the |
| 4650 |
result cannot fit in the ultimate object. This gives implementations more |
| 4651 |
flexibility to do built-in-place returns, and is essential for limited types |
| 4652 |
(which cannot be built in a temporary). However, it allows |
| 4653 |
raising @Chg{Version=[3],New=[],Old=[an ]} |
| 4654 |
Constraint_Error in some cases where it would not be raised if the |
| 4655 |
permission was not used. @Chg{Version=[3],New=[See @Inconsistent2005Title for |
| 4656 |
additional changes. ],Old=[]}This case is potentially inconsistent with Ada 95, but a compiler |
| 4657 |
does not have to take advantage of these permissions for any Ada 95 code, so |
| 4658 |
there should be little practical impact.]} |
| 4659 |
@end{Inconsistent95} |
| 4660 |
|
| 4661 |
@begin{Incompatible95} |
| 4662 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4663 |
@ChgAdded{Version=[2],Text=[@Defn{incompatibilities with Ada 95} The entire |
| 4664 |
business about return-by-reference types has been dropped. Instead, the |
| 4665 |
@nt{expression} of a return statement of a limited type can only be an |
| 4666 |
@nt{aggregate} or @nt{function_call} (see @RefSecNum{Limited Types}). This |
| 4667 |
means that returning a global object or @nt{type_conversion}, legal in Ada |
| 4668 |
95, is now illegal. Such functions can be converted to use anonymous access |
| 4669 |
return types by adding @key{access} in the function definition and return |
| 4670 |
statement, adding .@key{all} in uses, and adding @key{aliased} in the object |
| 4671 |
declarations. This has the advantage of making the reference return semantics |
| 4672 |
much clearer to the casual reader.]} |
| 4673 |
|
| 4674 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4675 |
@ChgAdded{Version=[2],Text=[We changed these rules so that functions, |
| 4676 |
combined with the new rules for limited types (@RefSecnum{Limited Types}), |
| 4677 |
can be used as build-in-place constructors for limited types. This reduces |
| 4678 |
the differences between limited and nonlimited types, which will |
| 4679 |
make limited types useful in more circumstances.]} |
| 4680 |
@end{Incompatible95} |
| 4681 |
|
| 4682 |
@begin{Extend95} |
| 4683 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4684 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 4685 |
The @nt{extended_return_statement} is new. This provides a name for |
| 4686 |
the object being returned, which reduces the copying needed to return |
| 4687 |
complex objects (including no copying at all for limited objects). It also |
| 4688 |
allows component-by-component construction of the return object.]} |
| 4689 |
@end{Extend95} |
| 4690 |
|
| 4691 |
@begin{DiffWord95} |
| 4692 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4693 |
@ChgAdded{Version=[2],Text=[The wording was updated to support anonymous |
| 4694 |
access return subtypes.]} |
| 4695 |
|
| 4696 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00318-02]} |
| 4697 |
@ChgAdded{Version=[2],Text=[The term @lquotes@;return expression@rquotes@; |
| 4698 |
was dropped because reviewers found it confusing when applied to the default |
| 4699 |
@nt{expression} of an @nt{extended_return_statement}.]} |
| 4700 |
|
| 4701 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00344-01],ARef=[AI95-00416-01]} |
| 4702 |
@ChgAdded{Version=[2],Text=[Added accessibility checks to class-wide |
| 4703 |
return statements. These checks could not fail in Ada 95 (as all of the |
| 4704 |
types had to be declared at the same level, so the tagged type would |
| 4705 |
necessarily have been at the same level as the type of the |
| 4706 |
object).]} |
| 4707 |
|
| 4708 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00402-01],ARef=[AI95-00416-01]} |
| 4709 |
@ChgAdded{Version=[2],Text=[Added accessibility checks to |
| 4710 |
return statements for types with access discriminants. Since such |
| 4711 |
types have to be limited in Ada 95, the @nt{expression} of a return statement |
| 4712 |
would have been illegal in order for this check to fail.]} |
| 4713 |
@end{DiffWord95} |
| 4714 |
|
| 4715 |
@begin{Inconsistent2005} |
| 4716 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0050-1]} |
| 4717 |
@ChgAdded{Version=[3],Text=[@Defn{inconsistencies with Ada 2005} |
| 4718 |
@b<Correction:> The @ImplPermName allowing early raising of Constraint_Error was modified |
| 4719 |
to remove the most common of these cases from the permission (returning an |
| 4720 |
object with mutable discriminants, where the return object is created with |
| 4721 |
one set of discriminants and then changed to another). (The permission was |
| 4722 |
also widened to allow the early check for constrained functions when that |
| 4723 |
constraint is wrong.) However, there still is an unlikely case where the |
| 4724 |
permission would allow an exception to be raised when none would be raised by the canonical |
| 4725 |
semantics (when a return statement is abandoned). These changes can only |
| 4726 |
remove the raising of an exception (or change the place where it is raised) |
| 4727 |
compared to Ada 2005, so programs that depend on the previous behavior should |
| 4728 |
be very rare.]} |
| 4729 |
|
| 4730 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0051-1],ARef=[AI05-0234-1]} |
| 4731 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Accessibility checks for |
| 4732 |
access discriminants now depend on the master of the call rather than |
| 4733 |
the point of declaration of the function. This will result in cases |
| 4734 |
that used to raise Program_Error now running without raising any exception. |
| 4735 |
This is technically inconsistent with Ada 2005 (as defined by Amendment 1), |
| 4736 |
but it is unlikely that any real code depends on the raising of this |
| 4737 |
exception.]} |
| 4738 |
|
| 4739 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0073-1]} |
| 4740 |
@ChgAdded{Version=[3],Text=[@b<Correction:> |
| 4741 |
Added a tag check for functions returning anonymous access-to-tagged types, |
| 4742 |
so that dispatching of tag-indeterminate function works as expected. |
| 4743 |
This is technically inconsistent with Ada 2005 (as defined by Amendment 1), |
| 4744 |
but as the feature in question was newly added to Ada 2005, there should |
| 4745 |
be little code that depends on the behavior that now raises an exception.]} |
| 4746 |
@end{Inconsistent2005} |
| 4747 |
|
| 4748 |
@begin{Incompatible2005} |
| 4749 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0053-1],ARef=[AI05-0277-1]} |
| 4750 |
@ChgAdded{Version=[3],Text=[@Defn{incompatibilities with Ada 2005}@b<Correction:> |
| 4751 |
The @key{aliased} keyword can now only appear on extended return objects |
| 4752 |
with an immutably limited type. Other types would provide a way to get |
| 4753 |
an aliased view of an object that is not necessarily aliased, which would be |
| 4754 |
very bad. This is incompatible, but since the feature was added in |
| 4755 |
Ada 2005, the keyword had no defined meaning in Ada 2005 |
| 4756 |
(a significant oversight), and most sensible uses involve immutably limited |
| 4757 |
types, it is unlikely that it appears meaningfully in existing programs.]} |
| 4758 |
|
| 4759 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0103-1]} |
| 4760 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Added wording to require |
| 4761 |
static matching for unconstrained access types in extended return statements. |
| 4762 |
This disallows adding or omitting null exclusions, and adding access |
| 4763 |
constraints, in the declaration of the return object. While this is |
| 4764 |
incompatible, the incompatible cases in question are either useless (access |
| 4765 |
constraints @en the constraint can be given on an @nt{allocator} if necessary, |
| 4766 |
and still must be given there even if given on the return object) |
| 4767 |
or wrong (null exclusions @en null could be returned from a |
| 4768 |
function declared to be null excluding), so we expect them to be extremely |
| 4769 |
rare in practice.]} |
| 4770 |
@end{Incompatible2005} |
| 4771 |
|
| 4772 |
@begin{Extend2005} |
| 4773 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0015-1],ARef=[AI05-0144-2]} |
| 4774 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 4775 |
The return object of an @nt{extended_return_statement} can be declared |
| 4776 |
constant; this works similarly to a constant object declaration.]} |
| 4777 |
|
| 4778 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0032-1]} |
| 4779 |
@ChgAdded{Version=[3],Text=[Added wording to allow |
| 4780 |
the @nt{return_subtype_indication} to have a specific type if the return |
| 4781 |
subtype of the function is class-wide. Specifying the (specific) type of |
| 4782 |
the return object is awkward without this change, and this is consistent |
| 4783 |
with the way @nt{allocator}s work.]} |
| 4784 |
@end{Extend2005} |
| 4785 |
|
| 4786 |
@begin{DiffWord2005} |
| 4787 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0024-1]} |
| 4788 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the master check |
| 4789 |
for tags since the masters may be for different tasks and thus incomparable.]} |
| 4790 |
|
| 4791 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0058-1]} |
| 4792 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the wording |
| 4793 |
defining returns for @nt{extended_return_statement}s, since leaving by |
| 4794 |
an exit or goto is considered @ldquote@;normal@rdquote completion of the |
| 4795 |
statement.]} |
| 4796 |
|
| 4797 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0205-1],ARef=[AI05-0277-1]} |
| 4798 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Added the |
| 4799 |
@nt{extended_return_object_declaration} to make other rules easier to write |
| 4800 |
and eliminate the problem described in AI05-0205-1.]} |
| 4801 |
@end{DiffWord2005} |
| 4802 |
|
| 4803 |
@begin{DiffWord2012} |
| 4804 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI05-0097-1]} |
| 4805 |
@ChgAdded{Version=[4],Text=[@b<Corrigendum:> Clarified the wording so that |
| 4806 |
it is clear where the tag of the return object comes from. While a literal |
| 4807 |
reading of the original Ada 2012 rule could have caused some weird results |
| 4808 |
(by using some nearby @nt{subtype_indication} to provide the tag in the |
| 4809 |
case of a @nt{simple_return_statement}, such a reading would be so unlike |
| 4810 |
the rest of the language that we do not believe anyone would ever have |
| 4811 |
thought it was intended. As such, we do not believe any implementation |
| 4812 |
ever did this wrong (at least because of the old wording), and thus do not |
| 4813 |
document this as a possible inconsistency.]} |
| 4814 |
@end{DiffWord2012} |
| 4815 |
|
| 4816 |
|
| 4817 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 4818 |
@LabeledRevisedSubClause{Version=[3],InitialVersion=[2],New=[Nonreturning Procedures],Old=[Pragma No_Return]} |
| 4819 |
|
| 4820 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 4821 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 4822 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Specifying aspect],Old=[A @nt{pragma}]} |
| 4823 |
No_Return @Chg{Version=[3],New=[to have the value True ],Old=[]}indicates |
| 4824 |
that a procedure cannot return normally@Redundant[; it may propagate |
| 4825 |
an exception or loop forever].]} |
| 4826 |
@begin{Discussion} |
| 4827 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4828 |
@ChgRef{Version=[3],Kind=[Revised]} |
| 4829 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Aspect],Old=[@nt{Pragma}]} |
| 4830 |
No_Deposit@Defn{No_Deposit aspect} will have to wait for |
| 4831 |
Ada @Chg{Version=[3],New=[2020],Old=[2017]}. :-)]} |
| 4832 |
@end{Discussion} |
| 4833 |
|
| 4834 |
@begin{NotIso} |
| 4835 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraphs 2 |
| 4836 |
and 3 were moved to @RefSec{Obsolescent Features}.>}]}@Comment{This message |
| 4837 |
should be deleted if the paragraphs are ever renumbered.} |
| 4838 |
@end{NotIso} |
| 4839 |
|
| 4840 |
@begin{Syntax} |
| 4841 |
@begin{SyntaxText} |
| 4842 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 4843 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 4844 |
@ChgAdded{Version=[2],Type=[Leading],Text=[@Chg{Version=[3],New=[],Old=[The form |
| 4845 |
of a @nt{pragma} No_Return, which is a |
| 4846 |
representation pragma (see @RefSecNum{Operational and Representation Aspects}), |
| 4847 |
is as follows:]}]} |
| 4848 |
@end{SyntaxText} |
| 4849 |
|
| 4850 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4851 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg]} |
| 4852 |
@DeletedPragmaSyn{Version=[3],InitialVersion=[2],@ChgAdded{Version=[2], |
| 4853 |
Text=`@Chg{Version=[3],New=[],Old=[@key{pragma} @prag<No_Return>(@SynI{procedure_}@Syn2{local_name}{, @SynI{procedure_}@Syn2{local_name}});]}'}} |
| 4854 |
@end{Syntax} |
| 4855 |
|
| 4856 |
@begin{StaticSem} |
| 4857 |
|
| 4858 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]} |
| 4859 |
@ChgAdded{Version=[3],Type=[Leading],Text=[For a procedure or generic procedure, the following |
| 4860 |
language-defined representation aspect may be specified:]} |
| 4861 |
@begin{Description} |
| 4862 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4863 |
@ChgAdded{Version=[3],Text=[No_Return@\The type of aspect No_Return is Boolean. |
| 4864 |
When aspect No_Return is True for an entity, the entity is said to be |
| 4865 |
@i<nonreturning>.@Defn{nonreturning}@AspectDefn{No_Return}]} |
| 4866 |
|
| 4867 |
@ChgRef{Version=[3],Kind=[Added]} |
| 4868 |
@ChgAdded{Version=[3],NoPrefix=[T],Text=[If directly specified, the |
| 4869 |
@nt{aspect_definition} shall be a static expression. @Redundant[This aspect is |
| 4870 |
never inherited;] if not directly specified, the aspect is False.]} |
| 4871 |
|
| 4872 |
@ChgAspectDesc{Version=[3],Kind=[AddedNormal],Aspect=[No_Return], |
| 4873 |
Text=[@ChgAdded{Version=[3],Text=[A procedure will not return normally.]}]} |
| 4874 |
@end{Description} |
| 4875 |
|
| 4876 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0229-1]}@ChgNote{Moved from below} |
| 4877 |
@ChgAdded{Version=[3],Text=[If a generic procedure is nonreturning, then so are |
| 4878 |
its instances. If a procedure declared within a generic unit is nonreturning, |
| 4879 |
then so are the corresponding copies of that procedure in instances.]} |
| 4880 |
|
| 4881 |
@end{StaticSem} |
| 4882 |
|
| 4883 |
|
| 4884 |
@begin{Legality} |
| 4885 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 4886 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 4887 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[Aspect No_Return], |
| 4888 |
Old=[@Defn{nonreturning}Each @SynI{procedure_}@nt{local_name} shall denote one |
| 4889 |
or more procedures or generic procedures; the denoted entities are |
| 4890 |
@i<nonreturning>. The @SynI{procedure_}@nt{local_name}]} shall not |
| 4891 |
@Chg{Version=[3],New=[be specified for],Old=[denote]} a |
| 4892 |
null procedure nor an instance of a generic unit.]} |
| 4893 |
|
| 4894 |
@begin{Reason} |
| 4895 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4896 |
@ChgAdded{Version=[2],Text=[A null procedure cannot have the appropriate |
| 4897 |
nonreturning semantics, as it does not raise an exception or loop forever.]} |
| 4898 |
@end{Reason} |
| 4899 |
|
| 4900 |
@begin{Ramification} |
| 4901 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4902 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 4903 |
@ChgAdded{Version=[2],Text=[The procedure can be abstract.@Chg{Version=[3],New=[], |
| 4904 |
Old=[ The denoted declaration can be a @nt{renaming_declaration} if it obeys the usual rules |
| 4905 |
for representation pragmas: the renaming has to occur immediately within the |
| 4906 |
same declarative region as the renamed subprogram.]} If a nonreturning |
| 4907 |
procedure is renamed (anywhere) calls through the new name still have the |
| 4908 |
nonreturning semantics.]} |
| 4909 |
@end{Ramification} |
| 4910 |
|
| 4911 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 4912 |
@ChgAdded{Version=[2],Text=[A return statement shall not apply to a |
| 4913 |
nonreturning procedure or generic procedure.]} |
| 4914 |
|
| 4915 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 4916 |
@ChgAdded{Version=[2],Text=[A procedure shall be nonreturning if it overrides |
| 4917 |
a dispatching nonreturning procedure. |
| 4918 |
@PDefn{generic contract issue} |
| 4919 |
In addition to the places where |
| 4920 |
@LegalityTitle normally apply (see @RefSecNum{Generic Instantiation}), |
| 4921 |
this rule applies also in the private part of an instance of a generic unit.]} |
| 4922 |
|
| 4923 |
@begin{Reason} |
| 4924 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4925 |
@ChgAdded{Version=[2],Text=[This ensures that dispatching calls to |
| 4926 |
nonreturning procedures will, in fact, not return.]} |
| 4927 |
@end{Reason} |
| 4928 |
|
| 4929 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00414-01]} |
| 4930 |
@ChgAdded{Version=[2],Text=[If a renaming-as-body completes a nonreturning |
| 4931 |
procedure declaration, then the renamed procedure shall be nonreturning.]} |
| 4932 |
|
| 4933 |
@begin{Reason} |
| 4934 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4935 |
@ChgAdded{Version=[2],Text=[This ensures that no extra code is needed to |
| 4936 |
implement the renames (that is, no wrapper is needed) as the body has |
| 4937 |
the same property.]} |
| 4938 |
@end{Reason} |
| 4939 |
|
| 4940 |
@end{Legality} |
| 4941 |
|
| 4942 |
@begin{NotIso} |
| 4943 |
@ChgAdded{Version=[3],Noprefix=[T],Noparanum=[T],Text=[@Shrink{@i<Paragraph 8 |
| 4944 |
was deleted.>}]}@Comment{This message should be deleted if the paragraphs |
| 4945 |
are ever renumbered.}@ChgNote{This special message is needed to get rid of |
| 4946 |
the old, now unused, subheader} |
| 4947 |
@end{NotIso} |
| 4948 |
|
| 4949 |
@begin{StaticSem} |
| 4950 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 4951 |
@ChgRef{Version=[3],Kind=[DeletedNoDelMsg],ARef=[AI05-0229-1]} |
| 4952 |
@ChgAdded{Version=[2],Text=[@Chg{Version=[3],New=[],Old=[If a generic procedure |
| 4953 |
is nonreturning, then so are its instances. If a procedure declared within |
| 4954 |
a generic unit is nonreturning, then so are the corresponding copies of |
| 4955 |
that procedure in instances.]}]} |
| 4956 |
@end{StaticSem} |
| 4957 |
|
| 4958 |
@begin{RunTime} |
| 4959 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 4960 |
@ChgAdded{Version=[2],Text=[If the body of a nonreturning procedure completes |
| 4961 |
normally, Program_Error is raised at the point of the call. |
| 4962 |
@Defn2{Term=[Program_Error],Sec=(raised by failure of run-time check)}]} |
| 4963 |
@end{RunTime} |
| 4964 |
@begin{Discussion} |
| 4965 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4966 |
@ChgAdded{Version=[2],Text=[Note that there is no name for suppressing |
| 4967 |
this check, since the check represents a bug, imposes no time overhead, |
| 4968 |
and minimal space overhead (since it can usually be statically eliminated |
| 4969 |
as dead code).]} |
| 4970 |
@end{Discussion} |
| 4971 |
@begin{ImplNote} |
| 4972 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4973 |
@ChgAdded{Version=[2],Text=[If a nonreturning procedure tries to return, we |
| 4974 |
raise Program_Error. This is stated as happening at the call site, because we |
| 4975 |
do not wish to allow the procedure to handle the exception (and then, |
| 4976 |
perhaps, try to return again!). However, the expected run-time model is that |
| 4977 |
the compiler will generate @key{raise} Program_Error at the end of the |
| 4978 |
procedure body (but not handleable by the procedure itself), as opposed to |
| 4979 |
doing it at the call site. (This is just like the typical run-time model for |
| 4980 |
functions that fall off the end without returning a value). The reason is |
| 4981 |
indirect calls: in P.@key{all}(...);, the compiler cannot know whether P |
| 4982 |
designates a nonreturning procedure or a normal one. Putting the @key{raise} |
| 4983 |
Program_Error in the procedure's generated code solves this problem neatly.]} |
| 4984 |
|
| 4985 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 4986 |
@ChgAdded{Version=[2],Text=[Similarly, if one passes a nonreturning |
| 4987 |
procedure to a generic formal parameter, the compiler cannot know this at |
| 4988 |
call sites (in shared code implementations); the raise-in-body solution |
| 4989 |
deals with this neatly.]} |
| 4990 |
@end{ImplNote} |
| 4991 |
|
| 4992 |
@begin{Examples} |
| 4993 |
@begin{Example} |
| 4994 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 4995 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0229-1]} |
| 4996 |
@ChgAdded{Version=[2],Text=[@key(procedure) Fail(Msg : String)@Chg{Version=[3],New=[],Old=[;]} --@ExamCom[ raises Fatal_Error exception] |
| 4997 |
@Chg{Version=[3],New=[ @key(with)],Old=[@key(pragma)]} No_Return@Chg{Version=[3],New=[],Old=[(Fail)]}; |
| 4998 |
--@ExamCom[ Inform compiler and reader that procedure never returns normally]]} |
| 4999 |
@end{Example} |
| 5000 |
@end{Examples} |
| 5001 |
|
| 5002 |
@begin{Extend95} |
| 5003 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00329-01],ARef=[AI95-00414-01]} |
| 5004 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 5005 |
@nt{Pragma} No_Return is new.]} |
| 5006 |
@end{Extend95} |
| 5007 |
|
| 5008 |
@begin{Extend2005} |
| 5009 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0229-1]} |
| 5010 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 5011 |
Aspect No_Return is new; @nt{pragma} No_Return is now obsolescent.]} |
| 5012 |
@end{Extend2005} |
| 5013 |
|
| 5014 |
|
| 5015 |
@NotISORMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 5016 |
@LabeledClause{Overloading of Operators} |
| 5017 |
|
| 5018 |
@begin{Intro} |
| 5019 |
@Defn{operator} |
| 5020 |
@Defn{user-defined operator} |
| 5021 |
@Defn2{Term=[operator], Sec=(user-defined)} |
| 5022 |
An @i{operator} is a function whose @nt{designator} is an |
| 5023 |
@nt<operator_symbol>. |
| 5024 |
@Redundant[Operators, like other functions, may be overloaded.] |
| 5025 |
@end{Intro} |
| 5026 |
|
| 5027 |
@begin{Resolution} |
| 5028 |
Each use of a unary or binary operator is equivalent to a |
| 5029 |
@nt{function_call} with @SynI{function_}@nt{prefix} being the |
| 5030 |
corresponding @nt{operator_symbol}, and with (respectively) one or |
| 5031 |
two positional actual parameters being the operand(s) of the operator |
| 5032 |
(in order). |
| 5033 |
@begin{Honest} |
| 5034 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0299-1]} |
| 5035 |
We also use the term operator |
| 5036 |
(in @Chg{Version=[3],New=[Clause],Old=[Section]} 4 and in |
| 5037 |
@RefSecNum{Subprogram Declarations}) |
| 5038 |
to refer to one of the syntactic categories |
| 5039 |
defined in @RefSec{Operators and Expression Evaluation} |
| 5040 |
whose names end with @lquotes@;_operator:@rquotes@; |
| 5041 |
@nt<logical_@!operator>, |
| 5042 |
@nt<relational_@!operator>, |
| 5043 |
@nt<binary_@!adding_@!operator>, |
| 5044 |
@nt<unary_@!adding_@!operator>, |
| 5045 |
@nt<multiplying_@!operator>, and |
| 5046 |
@nt<highest_@!precedence_@!operator>. |
| 5047 |
@end{Honest} |
| 5048 |
@begin{Discussion} |
| 5049 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0005-1]} |
| 5050 |
@ChgAdded{Version=[3],Text=[This equivalence extends to uses of |
| 5051 |
@nt{function_call} in most other language rules. However, as |
| 5052 |
often happens, the equivalence is not perfect, as operator |
| 5053 |
calls are not a @nt{name}, while a @nt{function_call} is a |
| 5054 |
@nt{name}. Thus, operator calls cannot be used in contexts |
| 5055 |
that require a @nt{name} (such as a rename of an object). |
| 5056 |
A direct fix for this problem would be very disruptive, and thus |
| 5057 |
we have not done that. However, qualifying an operator call |
| 5058 |
can be used as a workaround in contexts that require a @nt{name}.]} |
| 5059 |
@end{Discussion} |
| 5060 |
@end{Resolution} |
| 5061 |
|
| 5062 |
@begin{Legality} |
| 5063 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0143-1]} |
| 5064 |
The @nt{subprogram_specification} of a unary or binary operator shall have |
| 5065 |
one or two parameters, respectively.@Chg{Version=[3],New=[ The parameters |
| 5066 |
shall be of mode @key[in].],Old=[]} |
| 5067 |
A generic function instantiation whose @nt{designator} is an |
| 5068 |
@nt{operator_symbol} is only allowed if the specification of the |
| 5069 |
generic function has the corresponding number of |
| 5070 |
parameters@Chg{Version=[3],New=[, and they are all of mode @key[in]],Old=[]}. |
| 5071 |
|
| 5072 |
@nt{Default_expression}s are not allowed for the parameters of an operator |
| 5073 |
(whether the operator is declared with an explicit |
| 5074 |
@nt{subprogram_specification} or by a @nt{generic_instantiation}). |
| 5075 |
|
| 5076 |
An explicit declaration of "/=" shall not have a result |
| 5077 |
type of the predefined type Boolean. |
| 5078 |
@end{Legality} |
| 5079 |
|
| 5080 |
@begin{StaticSem} |
| 5081 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0128-1]} |
| 5082 |
@Chg{Version=[3],New=[An explicit],Old=[A]} declaration of "=" |
| 5083 |
whose result type is Boolean implicitly declares |
| 5084 |
@Chg{Version=[3],New=[an operator],Old=[a declaration of]} "/=" that |
| 5085 |
gives the complementary result.@Defn{/= operator} |
| 5086 |
@begin{Discussion} |
| 5087 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0128-1]} |
| 5088 |
@ChgAdded{Version=[3],Text=[A "/=" defined by this rule is considered |
| 5089 |
user-defined, which means that it will be inherited by a derived type. |
| 5090 |
@ldquote@;User-defined@rdquote means @ldquote@;not language-defined@rdquote for |
| 5091 |
the purposes of inheritance, that is anything other than predefined operators. |
| 5092 |
@Defn{Number of the Beast}@Comment{This is 6.6(6) :-)}]} |
| 5093 |
@end{Discussion} |
| 5094 |
@end{StaticSem} |
| 5095 |
|
| 5096 |
@begin{Notes} |
| 5097 |
The operators "+" and "@en@;" are both unary and binary operators, |
| 5098 |
and hence may be overloaded with both one- and two-parameter functions. |
| 5099 |
@end{Notes} |
| 5100 |
|
| 5101 |
@begin{Examples} |
| 5102 |
@leading@keepnext@i{Examples of user-defined operators:} |
| 5103 |
@begin{Example} |
| 5104 |
@key[function] "+" (Left, Right : Matrix) @key[return] Matrix; |
| 5105 |
@key[function] "+" (Left, Right : Vector) @key[return] Vector; |
| 5106 |
@Comment{Blank line} |
| 5107 |
--@ExamCom{ assuming that A, B, and C are of the type Vector} |
| 5108 |
--@ExamCom{ the following two statements are equivalent:} |
| 5109 |
@Comment{Blank line} |
| 5110 |
A := B + C; |
| 5111 |
A := "+"(B, C); |
| 5112 |
@end{Example} |
| 5113 |
@end{Examples} |
| 5114 |
|
| 5115 |
@begin{Extend83} |
| 5116 |
@Defn{extensions to Ada 83} |
| 5117 |
Explicit declarations of "=" are now permitted for any |
| 5118 |
combination of parameter and result types. |
| 5119 |
|
| 5120 |
Explicit declarations of "/=" are now permitted, so long |
| 5121 |
as the result type is not Boolean. |
| 5122 |
@end{Extend83} |
| 5123 |
|
| 5124 |
@begin{DiffWord2005} |
| 5125 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0128-1]} |
| 5126 |
@ChgAdded{Version=[3],Text=[@b<Correction:> Corrected the wording |
| 5127 |
so that only explicit declarations of "=" cause an implicit declaration |
| 5128 |
of "/="; otherwise, we could get multiple implicit definitions of "/=" |
| 5129 |
without an obvious way to chose between them.]} |
| 5130 |
|
| 5131 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0143-1]} |
| 5132 |
@ChgAdded{Version=[3],Text=[Added wording so that operators only allow |
| 5133 |
parameters of mode @key[in]. This was made necessary by the elimination |
| 5134 |
elsewhere of the restriction that function parameters be only of |
| 5135 |
mode @key[in].]} |
| 5136 |
@end{DiffWord2005} |
| 5137 |
|
| 5138 |
|
| 5139 |
@RMNewPageVer{Version=[2]}@Comment{For printed version of Ada 2005 RM} |
| 5140 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 5141 |
@LabeledAddedClause{Version=[2],Name=[Null Procedures]} |
| 5142 |
|
| 5143 |
@begin{Intro} |
| 5144 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 5145 |
@ChgAdded{Version=[2],Text=[A @nt<null_procedure_declaration> provides a shorthand |
| 5146 |
to declare a procedure with an empty body.]} |
| 5147 |
@end{Intro} |
| 5148 |
|
| 5149 |
@begin{Syntax} |
| 5150 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 5151 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0183-1]} |
| 5152 |
@AddedSyn{Version=[2],lhs=<@Chg{Version=[2],New=<null_procedure_declaration>,Old=<>}>, |
| 5153 |
rhs="@Chg{Version=[2],New=< |
| 5154 |
[@Syn2{overriding_indicator}] |
| 5155 |
@Syn2{procedure_specification} @key{is} @key{null}@Chg{Version=[3],New=< |
| 5156 |
[@Syn2{aspect_specification}]>,Old=[]};>,Old=<>}"} |
| 5157 |
@end{Syntax} |
| 5158 |
|
| 5159 |
@begin{Legality} |
| 5160 |
@ChgRef{Version=[3],Kind=[Added],ARef=[AI05-0177-1]} |
| 5161 |
@ChgAdded{Version=[3],Text=[If a @nt{null_procedure_declaration} is a completion, |
| 5162 |
it shall be the completion of a @nt{subprogram_declaration} or |
| 5163 |
@nt{generic_subprogram_declaration}. The profile of a |
| 5164 |
@nt{null_procedure_declaration} that completes a declaration shall |
| 5165 |
conform fully to that of the declaration.@Defn2{Term=[full conformance],Sec=(required)}]} |
| 5166 |
@end{Legality} |
| 5167 |
|
| 5168 |
@begin{StaticSem} |
| 5169 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 5170 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1],ARef=[AI05-0264-1]} |
| 5171 |
@ChgAdded{Version=[2],Text=[A @nt<null_procedure_declaration> declares a @i<null |
| 5172 |
procedure>.@Defn{null procedure}@Defn2{Term=[procedure],Sec=[null]} |
| 5173 |
A completion is not allowed for a @nt<null_procedure_declaration>@Chg{Version=[3],New=[; |
| 5174 |
however, a @nt{null_procedure_declaration} can complete a previous declaration],Old=[]}.]} |
| 5175 |
@begin{Reason} |
| 5176 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5177 |
@ChgAdded{Version=[2],Text=[There are no null functions because the return |
| 5178 |
value has to be constructed somehow; a function that always raises |
| 5179 |
Program_Error doesn't seem very useful or worth the complication.]} |
| 5180 |
@end{Reason} |
| 5181 |
@end{StaticSem} |
| 5182 |
|
| 5183 |
@begin{RunTime} |
| 5184 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 5185 |
@ChgAdded{Version=[2],Text=[The execution of a null procedure is invoked by a subprogram call. |
| 5186 |
For the execution of a subprogram call on a null procedure, the execution of |
| 5187 |
the @nt<subprogram_body> has no effect.]} |
| 5188 |
@begin{Ramification} |
| 5189 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5190 |
@ChgAdded{Version=[2],Text=[Thus, a null procedure is equivalent to the body]} |
| 5191 |
@begin{Example} |
| 5192 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5193 |
@ChgAdded{Version=[2],Text=[@key{begin} |
| 5194 |
@key{null}; |
| 5195 |
@key{end};]} |
| 5196 |
@end{Example} |
| 5197 |
@ChgRef{Version=[2],Kind=[AddedNormal]} |
| 5198 |
@ChgAdded{Version=[2],Text=[with the exception that a null procedure can be used in |
| 5199 |
place of a procedure specification.]} |
| 5200 |
@end{Ramification} |
| 5201 |
|
| 5202 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 5203 |
@ChgRef{Version=[3],Kind=[Revised],ARef=[AI05-0177-1]} |
| 5204 |
@ChgAdded{Version=[2],Text=[@PDefn2{Term=[elaboration], Sec=(null_procedure_declaration)} |
| 5205 |
The elaboration of a @nt{null_procedure_declaration} has no |
| 5206 |
@Chg{Version=[3],New=[other ],Old=[]}effect@Chg{Version=[3],New=[ than to |
| 5207 |
establish that the null procedure can be called without failing the |
| 5208 |
Elaboration_Check],Old=[]}.]} |
| 5209 |
@end{RunTime} |
| 5210 |
|
| 5211 |
@begin{Examples} |
| 5212 |
@begin{Example} |
| 5213 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00433-01]} |
| 5214 |
@ChgAdded{Version=[2],Text=[@key(procedure) Simplify(Expr : @key(in out) Expression) @key(is null); --@ExamCom[ see @RefSecNum{Tagged Types and Type Extensions}] |
| 5215 |
--@ExamCom[ By default, Simplify does nothing, but it may be overridden in extensions of Expression]]} |
| 5216 |
@end{Example} |
| 5217 |
@end{Examples} |
| 5218 |
|
| 5219 |
@begin{Extend95} |
| 5220 |
@ChgRef{Version=[2],Kind=[AddedNormal],ARef=[AI95-00348-01]} |
| 5221 |
@ChgAdded{Version=[2],Text=[@Defn{extensions to Ada 95} |
| 5222 |
Null procedures are new.]} |
| 5223 |
@end{Extend95} |
| 5224 |
|
| 5225 |
@begin{Extend2005} |
| 5226 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5227 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 5228 |
A @nt{null_procedure_declaration} can now be a completion.]} |
| 5229 |
|
| 5230 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0183-1]} |
| 5231 |
@ChgAdded{Version=[3],Text=[An optional @nt{aspect_specification} |
| 5232 |
can be used in a @nt{null_procedure_declaration}. |
| 5233 |
This is described in @RefSecNum{Aspect Specifications}.]} |
| 5234 |
@end{Extend2005} |
| 5235 |
|
| 5236 |
|
| 5237 |
@RMNewPageVer{Version=[3]}@Comment{For printed version of Ada 2012 RM} |
| 5238 |
@LabeledAddedClause{Version=[3],Name=[Expression Functions]} |
| 5239 |
|
| 5240 |
@begin{Intro} |
| 5241 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5242 |
@ChgAdded{Version=[3],Text=[An @nt{expression_function_declaration} provides a |
| 5243 |
shorthand to declare a function whose body consists of a single return |
| 5244 |
statement.]} |
| 5245 |
@end{Intro} |
| 5246 |
|
| 5247 |
@begin{Syntax} |
| 5248 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI95-0177-1]} |
| 5249 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI95-0147-1]} |
| 5250 |
@AddedSyn{Version=[3],lhs=<@Chg{Version=[3],New=<expression_function_declaration>,Old=<>}>, |
| 5251 |
rhs="@Chg{Version=[3],New=< |
| 5252 |
[@Syn2{overriding_indicator}] |
| 5253 |
@Syn2{function_specification} @key{is} |
| 5254 |
(@Syn2{expression}) |
| 5255 |
[@Syn2{aspect_specification}];@Chg{Version=[4],New=< |
| 5256 |
| [@Syn2{overriding_indicator}] |
| 5257 |
@Syn2{function_specification} @key{is} |
| 5258 |
@Syn2{aggregate} |
| 5259 |
[@Syn2{aspect_specification}];>,Old=<>}>,Old=<>}"} |
| 5260 |
@end{Syntax} |
| 5261 |
|
| 5262 |
@begin{Resolution} |
| 5263 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5264 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI95-0147-1]} |
| 5265 |
@ChgAdded{Version=[3],Text=[The expected type for the @nt{expression} |
| 5266 |
@Chg{Version=[4],New=[or @nt{aggregate} ],Old=[]}of an |
| 5267 |
@nt{expression_@!function_@!declaration} is the result type (see |
| 5268 |
@RefSecNum{Return Statements}) of the function.@PDefn2{Term=[expected type], |
| 5269 |
Sec=(expression of expression function)}]} |
| 5270 |
@end{Resolution} |
| 5271 |
|
| 5272 |
@begin{Legality} |
| 5273 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5274 |
@ChgAdded{Version=[3],Text=[If an @nt{expression_@!function_@!declaration} is a |
| 5275 |
completion, it shall be the completion of a @nt{subprogram_declaration} or |
| 5276 |
@nt{generic_subprogram_declaration}. The profile of an |
| 5277 |
@nt{expression_@!function_@!declaration} that completes a declaration |
| 5278 |
shall conform fully to that of the declaration.@Defn2{Term=[full conformance],Sec=(required)}]} |
| 5279 |
|
| 5280 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5281 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI95-0147-1]} |
| 5282 |
@ChgAdded{Version=[3],Text=[If the result subtype has one or more unconstrained |
| 5283 |
access discriminants, the accessibility level of the anonymous access type of |
| 5284 |
each access discriminant, as determined by the @nt{expression} |
| 5285 |
@Chg{Version=[4],New=[or @nt{aggregate} ],Old=[]}of the |
| 5286 |
@Chg{Version=[4],New=[@nt{expression_@!function_@!declaration}],Old=[expression |
| 5287 |
function]}, shall not be statically deeper than that of the master that |
| 5288 |
elaborated the @nt{expression_@!function_@!declaration}.]} |
| 5289 |
|
| 5290 |
@begin{Ramification} |
| 5291 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5292 |
@ChgAdded{Version=[3],Text=[This can only fail if the discriminant is an |
| 5293 |
access to a part of a non-aliased parameter, as there can be no local |
| 5294 |
declarations here.]} |
| 5295 |
@end{Ramification} |
| 5296 |
|
| 5297 |
@begin{Discussion} |
| 5298 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5299 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI12-0005-1]} |
| 5300 |
@ChgAdded{Version=[3],Text=[We don't need to repeat any of the other |
| 5301 |
@LegalityTitle for return statements since none of them can fail here: the |
| 5302 |
implicit return statement has to apply to this function (and isn't nested in |
| 5303 |
something), there clearly is a return statement in this function, and the |
| 5304 |
static @Chg{Version=[4],New=[class-wide],Old=[classwide]} accessibility check |
| 5305 |
cannot fail as a tagged type cannot be |
| 5306 |
declared locally in an expression function.]} |
| 5307 |
@end{Discussion} |
| 5308 |
@end{Legality} |
| 5309 |
|
| 5310 |
@begin{StaticSem} |
| 5311 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1],ARef=[AI05-0264-1]} |
| 5312 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI95-0147-1]} |
| 5313 |
@ChgAdded{Version=[3],Text=[An @nt{expression_@!function_@!declaration} declares |
| 5314 |
an @i{expression function}.@Defn{expression function}@Defn2{Term=[function],Sec=[expression]} |
| 5315 |
@Chg{Version=[4],New=[The @i<return expression>@Defn2{Term=[return expression],Sec=[of expression function]} |
| 5316 |
of an expression function is the @nt{expression} or @nt{aggregate} of the |
| 5317 |
@nt{expression_function_declaration}. ],Old=[]}A completion |
| 5318 |
is not allowed for an @nt{expression_@!function_@!declaration}; however, an |
| 5319 |
@nt{expression_@!function_@!declaration} can complete a previous declaration.]} |
| 5320 |
@end{StaticSem} |
| 5321 |
|
| 5322 |
@begin{RunTime} |
| 5323 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1],ARef=[AI05-0262-1]} |
| 5324 |
@ChgRef{Version=[4],Kind=[Revised],ARef=[AI95-0147-1]} |
| 5325 |
@ChgAdded{Version=[3],Text=[ The execution of an expression function is invoked |
| 5326 |
by a subprogram call. For the execution of a subprogram call on an expression |
| 5327 |
function, the execution of the @nt{subprogram_body} executes an implicit |
| 5328 |
function body containing only a @nt{simple_return_statement} whose |
| 5329 |
@nt{expression} is @Chg{Version=[4],New=[the return expression],Old=[that]} |
| 5330 |
of the expression function.]} |
| 5331 |
|
| 5332 |
@begin{Discussion} |
| 5333 |
@ChgRef{Version=[3],Kind=[AddedNormal]} |
| 5334 |
@ChgAdded{Version=[3],Text=[The last sentence effectively means that all of |
| 5335 |
the dynamic wording in @RefSecNum{Return Statements} applies as needed, and we |
| 5336 |
don't have to repeat it here.]} |
| 5337 |
@end{Discussion} |
| 5338 |
|
| 5339 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5340 |
@ChgAdded{Version=[3],Text=[@PDefn2{Term=[elaboration], |
| 5341 |
Sec=(expression_function_declaration)}The elaboration of an |
| 5342 |
@nt{expression_@!function_@!declaration} has no other effect than to establish |
| 5343 |
that the expression function can be called without failing the |
| 5344 |
Elaboration_Check.]} |
| 5345 |
@end{RunTime} |
| 5346 |
|
| 5347 |
@begin{Examples} |
| 5348 |
@begin{Example} |
| 5349 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5350 |
@ChgAdded{Version=[3],Text=[@key(function) Is_Origin (P : @key[in] Point) @key[return] Boolean @key[is] -- @Examcom[see @RefSecNum{Tagged Types and Type Extensions}] |
| 5351 |
(P.X = 0.0 @key[and] P.Y = 0.0);]} |
| 5352 |
@end{Example} |
| 5353 |
@end{Examples} |
| 5354 |
|
| 5355 |
@begin{Extend2005} |
| 5356 |
@ChgRef{Version=[3],Kind=[AddedNormal],ARef=[AI05-0177-1]} |
| 5357 |
@ChgAdded{Version=[3],Text=[@Defn{extensions to Ada 2005} |
| 5358 |
Expression functions are new in Ada 2012.]} |
| 5359 |
@end{Extend2005} |
| 5360 |
|
| 5361 |
@begin{Extend2012} |
| 5362 |
@ChgRef{Version=[4],Kind=[AddedNormal],ARef=[AI12-0157-1]} |
| 5363 |
@ChgAdded{Version=[4],Text=[@Defn{extensions to Ada 2012} |
| 5364 |
A @nt{aggregate} can directly be the return expression of an expression |
| 5365 |
function. This eliminates the double parentheses that otherwise would be |
| 5366 |
necessary.]} |
| 5367 |
@end{Extend2012} |
| 5368 |
|