https://gcc.gnu.org/g:8a419accb7741c317cede9466c369666d2ee2462

commit r16-1165-g8a419accb7741c317cede9466c369666d2ee2462
Author: Ronan Desplanques <desplanq...@adacore.com>
Date:   Mon Feb 3 14:22:22 2025 +0100

    ada: Fix SFN_Patterns documentation comment
    
    The documentation comment under SFN_Patterns was misleading. This patch
    fixes it and also fixes Get_Default_File_Name which assumed the comment
    was correct.
    
    gcc/ada/ChangeLog:
    
            * fname-uf.adb: Fix documentation comment.
            (Get_Default_File_Name): Fix indices of default patterns.

Diff:
---
 gcc/ada/fname-uf.adb | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/gcc/ada/fname-uf.adb b/gcc/ada/fname-uf.adb
index 39a09c4ce133..ec22ad7a3d2a 100644
--- a/gcc/ada/fname-uf.adb
+++ b/gcc/ada/fname-uf.adb
@@ -90,8 +90,9 @@ package body Fname.UF is
      Table_Initial        => 10,
      Table_Increment      => 100,
      Table_Name           => "SFN_Patterns");
-   --  Table recording calls to Set_File_Name_Pattern. Note that the first two
-   --  entries are set to represent the standard GNAT rules for file naming.
+   --  Table recording calls to Set_File_Name_Pattern. Note that the last two
+   --  entries are set to represent the standard GNAT rules for file naming;
+   --  that invariant is maintained by Set_File_Name_Pattern.
 
    procedure Instantiate_SFN_Pattern
      (Pattern   : SFN_Pattern_Entry;
@@ -178,6 +179,8 @@ package body Fname.UF is
    ---------------------------
 
    function Get_Default_File_Name (Uname : Unit_Name_Type) return String is
+      L : constant Int := SFN_Patterns.Last;
+
       Buf : Bounded_String;
 
       Pattern : SFN_Pattern_Entry;
@@ -185,10 +188,10 @@ package body Fname.UF is
       Get_Unit_Name_String (Buf, Uname, False);
 
       if Is_Spec_Name (Uname) then
-         Pattern := SFN_Patterns.Table (1);
+         Pattern := SFN_Patterns.Table (L - 1);
       else
          pragma Assert (Is_Body_Name (Uname));
-         Pattern := SFN_Patterns.Table (2);
+         Pattern := SFN_Patterns.Table (L);
       end if;
 
       Instantiate_SFN_Pattern (Pattern, Buf);

Reply via email to