]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ada: Make "finally" a non-reserved keyword
authorRonan Desplanques <desplanques@adacore.com>
Wed, 7 Jan 2026 11:43:36 +0000 (12:43 +0100)
committerMarc Poulhiès <dkm@gcc.gnu.org>
Mon, 25 May 2026 08:28:07 +0000 (10:28 +0200)
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.

gcc/ada/doc/gnat_rm/gnat_language_extensions.rst
gcc/ada/gnat_rm.texi
gcc/ada/par-ch5.adb
gcc/ada/par-util.adb
gcc/ada/scans.adb
gcc/ada/snames.adb-tmpl
gcc/ada/snames.ads-tmpl

index cd5391e6f69d7fed00034c16ff03f140aaa3a3a4..40a7a8039a5047175b2da0c4dfaa4c0177b41282 100644 (file)
@@ -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
 ^^^^^^
 
index 74c8f747b49cde3dcf85092995ed50b6de86adb4..6f8d729d806f618bec93bd62f3560113186371b1 100644 (file)
@@ -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:
 
index a327e7178198f60195167736a6e47277dccd9e1c..e9dfec36d8f673a03255afc1d239c1dd037bae87 100644 (file)
@@ -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
index c9d8920327ef771540e2d0d4d7da838e75ab3b5a..790d238696c6a8e5dd8d82244e0966ebe5aff0d1 100644 (file)
@@ -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.
index 5c1b6ccba77f43dcda6080870e6b6b9723a7b64c..80d6924d4dcb55ceb1bcb4b957cb5fdb08eb7cf3 100644 (file)
@@ -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;
 
    ------------------
index f1deb9e6521e95e7d148a573453b11d79e41c59d..28a0c9a9d18a29e8e057d0b92eaffbb5d0b9e0e7 100644 (file)
@@ -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;
 
    --------------------------------
index 6d0ab5eeecff2f65e52e91ed2addaac0227de176..70c5941e3bb37afdd09989b33c962ddfd52f67cd 100644 (file)
@@ -1409,6 +1409,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
 
@@ -1457,16 +1458,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 + $;