https://gcc.gnu.org/g:d0aa904d265a223f53c5aec551d129c55dc33bd4
commit r16-8973-gd0aa904d265a223f53c5aec551d129c55dc33bd4 Author: Ronan Desplanques <[email protected]> Date: Wed Jan 7 12:43:36 2026 +0100 ada: Make "finally" a non-reserved keyword This makes it possible to use the word "finally" as an identifier when GNAT extensions are enabled. This does not make the syntax ambiguous and the "finally" syntax extension is not affected. gcc/ada/ChangeLog: * doc/gnat_rm/gnat_language_extensions.rst: Add that finally is a non-reserved keyword. * par-ch5.adb (P_Sequence_Of_Statements): handle "finally" syntax extension. * snames.ads-tmpl: Remove the concept of GNAT extension reserved word. * snames.adb-tmpl (Is_Keyword_Name): Likewise. * scans.adb (Initialize_Ada_Keywords): Likewise. * par-util.adb (Check_Future_Keyword): Likewise. * gnat_rm.texi: Regenerate. Diff: --- gcc/ada/doc/gnat_rm/gnat_language_extensions.rst | 3 +++ gcc/ada/gnat_rm.texi | 30 ++++++++++++++---------- gcc/ada/par-ch5.adb | 30 ++++++++++++++++++------ gcc/ada/par-util.adb | 8 ------- gcc/ada/scans.adb | 3 --- gcc/ada/snames.adb-tmpl | 4 +--- gcc/ada/snames.ads-tmpl | 11 +-------- 7 files changed, 45 insertions(+), 44 deletions(-) diff --git a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst index cd5391e6f69d..40a7a8039a50 100644 --- a/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst +++ b/gcc/ada/doc/gnat_rm/gnat_language_extensions.rst @@ -1746,6 +1746,9 @@ another sequence of statements is completed, whether normally or abnormally. 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 ^^^^^^ diff --git a/gcc/ada/gnat_rm.texi b/gcc/ada/gnat_rm.texi index 74c8f747b49c..6f8d729d806f 100644 --- a/gcc/ada/gnat_rm.texi +++ b/gcc/ada/gnat_rm.texi @@ -19,7 +19,7 @@ @copying @quotation -GNAT Reference Manual , Jan 09, 2026 +GNAT Reference Manual , May 19, 2026 AdaCore @@ -11300,13 +11300,15 @@ prefix) yields a static Boolean value that is True if pragma @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. @@ -30625,7 +30627,7 @@ RM references: 3.03 (23.2/3) 8.05.01 (4.7/5) 8.05.01 (5/3) @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 @@ -32842,6 +32844,9 @@ another sequence of statements is completed, whether normally or abnormally. 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>. @@ -33036,7 +33041,6 @@ actual parameters. This instance is unique to a partition, except when a generic subprogram instantiation is automatically demoted to a local instantiation as described under Legality Rules. - Example: @example @@ -33073,11 +33077,11 @@ package Q is 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; @@ -33133,11 +33137,11 @@ package body Q is 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: diff --git a/gcc/ada/par-ch5.adb b/gcc/ada/par-ch5.adb index a327e7178198..e9dfec36d8f6 100644 --- a/gcc/ada/par-ch5.adb +++ b/gcc/ada/par-ch5.adb @@ -720,11 +720,21 @@ package body Ch5 is 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, @@ -758,8 +768,14 @@ package body Ch5 is 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 diff --git a/gcc/ada/par-util.adb b/gcc/ada/par-util.adb index c9d8920327ef..790d238696c6 100644 --- a/gcc/ada/par-util.adb +++ b/gcc/ada/par-util.adb @@ -230,14 +230,6 @@ package body Util is 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. diff --git a/gcc/ada/scans.adb b/gcc/ada/scans.adb index af6ec550cfa6..bb160380d0e6 100644 --- a/gcc/ada/scans.adb +++ b/gcc/ada/scans.adb @@ -134,9 +134,6 @@ package body Scans is -- Ada 2012 reserved words Set_Reserved (Name_Some, Tok_Some); - - -- GNAT extensions reserved words - Set_Reserved (Name_Finally, Tok_Finally); end Initialize_Ada_Keywords; ------------------ diff --git a/gcc/ada/snames.adb-tmpl b/gcc/ada/snames.adb-tmpl index f1deb9e6521e..28a0c9a9d18a 100644 --- a/gcc/ada/snames.adb-tmpl +++ b/gcc/ada/snames.adb-tmpl @@ -458,9 +458,7 @@ package body Snames is -- 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; -------------------------------- diff --git a/gcc/ada/snames.ads-tmpl b/gcc/ada/snames.ads-tmpl index 510fac92ec00..405803f23c51 100644 --- a/gcc/ada/snames.ads-tmpl +++ b/gcc/ada/snames.ads-tmpl @@ -1406,6 +1406,7 @@ package Snames is 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 @@ -1454,16 +1455,6 @@ package Snames is 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 + $;
