This feature is similar to the one with the same name in other languages such as Java.
+Note that ``finally`` is a keyword but it is not a reserved word. This is a
+configuration that does not exist in standard Ada.
+
Syntax
^^^^^^
@copying
@quotation
-GNAT Reference Manual , Jan 09, 2026
+GNAT Reference Manual , May 19, 2026
AdaCore
@geindex Finalization_Size
The prefix of attribute @code{Finalization_Size} must be an object or
-a non-class-wide type. This attribute returns the size of any hidden data
+a type. This attribute returns the size of any hidden data
reserved by the compiler to handle finalization-related actions. The type of
the attribute is `universal_integer'.
@code{Finalization_Size} yields a value of zero for a type with no controlled
parts, an object whose type has no controlled parts, or an object of a
class-wide type whose tag denotes a type with no controlled parts.
+For a class-wide type, @code{Finalization_Size} yields a non-zero value except
+if a No_Finalization restriction is in effect, in which case it yields zero.
Note that only heap-allocated objects contain finalization data.
@itemize *
-@item
+@item
`AI12-0402 Master of a function call with elementary result type (2026-01-07)'
This AI restricts the rule that makes the master of a function call, which
This feature is similar to the one with the same name in other languages such as Java.
+Note that @code{finally} is a keyword but it is not a reserved word. This is a
+configuration that does not exist in standard Ada.
+
@menu
* Syntax: Syntax<2>.
* Legality Rules: Legality Rules<2>.
generic subprogram instantiation is automatically demoted to a local
instantiation as described under Legality Rules.
-
Example:
@example
end Q;
@end example
-The reason is that @code{Ada.Containers.Vectors}, @code{Positive} and @code{Q.T}
-being library-level entities, the structural instance @code{Ada.Containers.Vectors(Positive,T)} is a library unit with a dependence
+The reason is that @code{Ada.Containers.Vectors}, @code{Positive} and @code{Q.T} being
+library-level entities, the structural instance @code{Ada.Containers.Vectors(Positive,T)} is a library unit with a dependence
on @code{Q} and, therefore, cannot be referenced from within @code{Q}. This
-restriction applies to structural instantiations of generic packages. The simple
-way out is to declare a traditional instantiation in this case:
+restriction applies to structural instantiations of generic packages. The
+simple way out is to declare a traditional instantiation in this case:
@example
with Ada.Containers.Vectors;
end Q;
@end example
-is legal: since @code{T} and @code{T_Access} are local entities of @code{Q},
-the structural instantiation of @code{Ada.Unchecked_Deallocation} is demoted
-to a local instantiation rather than producing an error. Note that the
-uniqueness guarantee no longer holds in this case and several instances of
-the generic subprogram may be present in a single partition.
+is legal: since @code{T} and @code{T_Access} are local entities of @code{Q}, the
+structural instantiation of @code{Ada.Unchecked_Deallocation} is demoted to a
+local instantiation rather than producing an error. Note that the uniqueness
+guarantee no longer holds in this case and several instances of the generic
+subprogram may be present in a single partition.
The first example can be rewritten in a less verbose manner:
Statement_Required := False;
end if;
- -- If junk after identifier, check if identifier is an
- -- instance of an incorrectly spelled keyword. If so, we
- -- do nothing. The Bad_Spelling_Of will have reset Token
- -- to the appropriate keyword, so the next time round the
- -- loop we will process the modified token.
+ -- If junk after identifier, check if identifier is one of:
+ --
+ -- - An instance of an incorrectly spelled keyword.
+ -- - One of the non-reserved keywords introduced by GNAT
+ -- syntax extensions (currently, "finally" is the only
+ -- such keyword that can occur here).
+ --
+ -- In the incorrect spelling case, we do nothing.
+ -- Bad_Spelling_Of will have reset Token to the appropriate
+ -- keyword, so the next time round the loop we will process
+ -- the modified token.
+ --
+ -- In the non-reserved keyword case, we replace the
+ -- identifier token with a token for the appropriate
+ -- keyword.
--
-- Note that we check for ELSIF before ELSE here, because
-- we don't want to identify a misspelling of ELSE as ELSIF,
or else Bad_Spelling_Of (Tok_While)
then
null;
-
- -- If not a bad spelling, then we really have junk
+ elsif Token_Name = Name_Finally then
+ Error_Msg_GNAT_Extension
+ ("the finally construct", Token_Ptr);
+ Token := Tok_Finally;
+ exit;
+
+ -- If not a bad spelling or non-reserved keyword, then we
+ -- really have junk.
else
Scan; -- past identifier again
end if;
end if;
- if Ada_Version < Ada_With_All_Extensions then
- if Token_Name in GNAT_Extensions_Reserved_Words then
- Error_Msg_N
- ("& is a reserved word with all extensions enabled?",
- Token_Node);
- end if;
- end if;
-
-- Note: we deliberately do not emit these warnings when operating in
-- Ada 83 mode because in that case we assume the user is building
-- legacy code anyway and is not interested in updating Ada versions.
-- Ada 2012 reserved words
Set_Reserved (Name_Some, Tok_Some);
-
- -- GNAT extensions reserved words
- Set_Reserved (Name_Finally, Tok_Finally);
end Initialize_Ada_Keywords;
------------------
-- for compatibility with Ada 95 compilers implementing
-- only this Ada 2005 extension.
and then (Ada_Version >= Ada_2012
- or else N not in Ada_2012_Reserved_Words)
- and then (Ada_Version >= Ada_With_All_Extensions
- or else N not in GNAT_Extensions_Reserved_Words);
+ or else N not in Ada_2012_Reserved_Words);
end Is_Keyword_Name;
--------------------------------
Name_Synchronous_Task_Control : constant Name_Id := N + $;
Name_Continue : constant Name_Id := N + $;
+ Name_Finally : constant Name_Id := N + $;
-- Names used to implement iterators over predefined containers
subtype Ada_2012_Reserved_Words is Name_Id
range First_2012_Reserved_Word .. Last_2012_Reserved_Word;
- -- GNAT extensions reserved words
-
- First_GNAT_Extensions_Reserved_Word : constant Name_Id := N + $;
- Name_Finally : constant Name_Id := N + $;
- Last_GNAT_Extensions_Reserved_Word : constant Name_Id := N + $;
-
- subtype GNAT_Extensions_Reserved_Words is Name_Id
- range First_GNAT_Extensions_Reserved_Word ..
- Last_GNAT_Extensions_Reserved_Word;
-
-- Mark last defined name for consistency check in Snames body
Last_Predefined_Name : constant Name_Id := N + $;