From 7281c10180d67547128589d7b65360e674cb500f Mon Sep 17 00:00:00 2001
From: Nicolas Boulenguez <nicolas.boulenguez@free.fr>
Date: Fri, 3 Jun 2016 02:34:28 +0200
Subject: [PATCH 17/20] Fix many warnings, and use return blocks in
 util-text.adb. The return block avoids a temporary copy of a controlled
 object during every string affectation and should enhance the efficiency.

---
 debian/patches/fix-warnings.diff      | 426 ++++++++++++++++++++++++++++++++++
 debian/patches/series                 |   2 +
 debian/patches/use-return-blocks.diff | 347 +++++++++++++++++++++++++++
 3 files changed, 775 insertions(+)
 create mode 100644 debian/patches/fix-warnings.diff
 create mode 100644 debian/patches/use-return-blocks.diff

diff --git a/debian/patches/fix-warnings.diff b/debian/patches/fix-warnings.diff
new file mode 100644
index 0000000..9f075c9
--- /dev/null
+++ b/debian/patches/fix-warnings.diff
@@ -0,0 +1,426 @@
+Description: fix many GNAT warnings.
+Author: Nicolas Boulenguez <nicolas@debian.org>
+
+--- a/ad-crossrefs.adb
++++ b/ad-crossrefs.adb
+@@ -47,9 +47,7 @@
+ 
+ with Ada.Characters.Handling;
+ with Ada.Exceptions;
+-with Ada.Strings.Wide_Unbounded;
+ 
+-with Asis;
+ with Asis.Clauses;
+ with Asis.Compilation_Units;
+ with Asis.Declarations;
+@@ -62,7 +60,6 @@
+ 
+ with Asis2.Declarations;
+ with Asis2.Naming;
+-with Asis2.Spans;
+ with Asis2.Text;
+ with Asis2.Units;
+ 
+--- a/ad-descriptions.adb
++++ b/ad-descriptions.adb
+@@ -56,9 +56,6 @@
+ with Asis;
+ with Asis.Declarations;
+ with Asis.Elements;
+-with Asis.Text;
+-
+-with Asis2.Spans;
+ 
+ with Util.Strings;
+ 
+@@ -743,4 +740,3 @@
+       end if;
+    end loop;
+ end AD.Descriptions;
+-
+--- a/ad-driver.adb
++++ b/ad-driver.adb
+@@ -696,7 +696,6 @@
+    procedure Report
+      (Debug_Only : Boolean := False)
+    is
+-      use type AD.Messages.Verbosity;
+    begin
+       if not Debug_Only or else
+          AD.Messages.Get_Mode = AD.Messages.Including_Debug
+@@ -1142,8 +1141,6 @@
+       AD.Printers.Free (The_Printer);
+ 
+       declare
+-         use type Ada.Text_IO.File_Access;
+-
+          procedure Free is
+             new Ada.Unchecked_Deallocation
+                   (Ada.Text_IO.File_Type, File_Ptr);
+--- a/ad-exclusions.adb
++++ b/ad-exclusions.adb
+@@ -75,7 +75,7 @@
+       use type ASU.Unbounded_String;
+ 
+       P, Q : Exclusion_Ptr;
+-      K    : ASU.Unbounded_String := ASU.To_Unbounded_String (Key);
++      K    : constant ASU.Unbounded_String := ASU.To_Unbounded_String (Key);
+    begin
+       P := Anchor;
+       while P /= null loop
+--- a/ad-expressions.adb
++++ b/ad-expressions.adb
+@@ -266,8 +266,7 @@
+          elsif Text (Curr) = '@' then
+             Curr := Curr + 1;
+             return Op_Prefix;
+-         elsif Curr < Text'Last and then
+-               Text (Curr .. Curr + 1) = "/=" then
++         elsif Curr < Text'Last and then Text (Curr .. Curr + 1) = "/=" then
+             Curr := Curr + 2;
+             return Op_Neq;
+          else
+@@ -656,7 +655,7 @@
+         (Name : in String;
+          Expr : in Exp'Class)
+       is
+-         E : Expression :=
++         E : constant Expression :=
+            (Ada.Finalization.Controlled with Ptr => new Exp'Class'(Expr));
+       begin
+          Hashing.Insert (Predef, Name, E);
+--- a/ad-filters.adb
++++ b/ad-filters.adb
+@@ -64,7 +64,6 @@
+ with Ada.Exceptions;
+ with Ada.Streams.Stream_IO;
+ with Ada.Text_IO;
+-with Ada.Unchecked_Deallocation;
+ 
+ with AD.File_Ops;
+ with AD.HTML;
+@@ -2497,5 +2496,3 @@
+    end Transform;
+ 
+ end AD.Filters;
+-
+-
+--- a/ad-format.adb
++++ b/ad-format.adb
+@@ -45,7 +45,6 @@
+ with Ada.Characters.Handling;
+ with Ada.Unchecked_Deallocation;
+ 
+-with AD.Filters;
+ --  with AD.Messages;
+ 
+ with Util.Strings;
+--- a/ad-html-pathes.adb
++++ b/ad-html-pathes.adb
+@@ -73,7 +73,7 @@
+       use type ASU.Unbounded_String;
+ 
+       P, Q : Path_Ptr;
+-      K    : ASU.Unbounded_String :=
++      K    : constant ASU.Unbounded_String :=
+         ASU.To_Unbounded_String (To_Lower (Key));
+    begin
+       P := Anchor;
+--- a/ad-html.adb
++++ b/ad-html.adb
+@@ -60,7 +60,6 @@
+ with Ada.Strings.Fixed;
+ with Ada.Strings.Maps;
+ with Ada.Strings.Unbounded;
+-with Ada.Text_IO;
+ 
+ with AD.Config;
+ with AD.Version;
+@@ -583,5 +582,3 @@
+    Ending (After) :=
+      ASU.To_Unbounded_String ("</FONT></TD></TR></TABLE>");
+ end AD.HTML;
+-
+-
+--- a/ad-indices.adb
++++ b/ad-indices.adb
+@@ -41,13 +41,9 @@
+ pragma License (GPL);
+ 
+ with Ada.Characters.Handling;
+-with Ada.Finalization;
+-with Ada.Strings.Maps;
+-with Ada.Strings.Unbounded;
+ with Ada.Strings.Wide_Unbounded;
+ with Ada.Unchecked_Deallocation;
+ 
+-with Asis;
+ with Asis.Declarations;
+ with Asis.Elements;
+ 
+@@ -55,13 +51,10 @@
+ with Asis2.Naming;
+ with Asis2.Spans;
+ 
+-with AD.Crossrefs;
+ with AD.Exclusions;
+-with AD.Expressions;
+ with AD.Messages;
+ with AD.Options;
+ with AD.Predicates;
+-with AD.Printers;
+ with AD.Text_Utilities;
+ 
+ with GAL.ADT.Hash_Tables;
+--- a/ad-item_lists.adb
++++ b/ad-item_lists.adb
+@@ -59,20 +59,16 @@
+ 
+ with Ada.Unchecked_Deallocation;
+ 
+-with Asis;
+ with Asis.Clauses;
+ with Asis.Elements;
+ with Asis.Exceptions;
+ with Asis.Expressions;
+-with Asis.Text;
+ 
+ with Asis2.Container_Elements;
+ with Asis2.Declarations;
+ with Asis2.Naming;
+-with Asis2.Spans;
+ with Asis2.Text;
+ 
+-with AD.Descriptions;
+ with AD.Options;
+ with AD.Queries;
+ 
+@@ -689,4 +685,3 @@
+    end Collect_Subordinates;
+ 
+ end AD.Item_Lists;
+-
+--- a/ad-parameters.adb
++++ b/ad-parameters.adb
+@@ -45,7 +45,6 @@
+ with Ada.Strings.Fixed;
+ with Ada.Strings.Maps;
+ with Ada.Strings.Unbounded;
+-with Ada.Text_IO;
+ 
+ with AD.Known_Units;
+ with AD.Text_Utilities;
+--- a/ad-printers-html.adb
++++ b/ad-printers-html.adb
+@@ -47,8 +47,6 @@
+ with Ada.Strings.Wide_Unbounded;
+ with Ada.Unchecked_Deallocation;
+ 
+-with Asis.Text;
+-
+ with Asis2.Spans;
+ 
+ with AD.Format;
+--- a/ad-printers.adb
++++ b/ad-printers.adb
+@@ -38,11 +38,9 @@
+ pragma License (GPL);
+ 
+ with Ada.Exceptions;
+-with Ada.Text_IO;
+ 
+ with Asis.Declarations;
+ with Asis.Elements;
+-with Asis.Text;
+ 
+ with AD.File_Ops;
+ with AD.Messages;
+--- a/ad-queries.adb
++++ b/ad-queries.adb
+@@ -72,7 +72,6 @@
+ 
+ with Ada.Unchecked_Deallocation;
+ 
+-with Asis;
+ with Asis.Compilation_Units.Relations;
+ with Asis.Definitions;
+ with Asis.Declarations;
+--- a/ad-scanner.adb
++++ b/ad-scanner.adb
+@@ -233,11 +233,9 @@
+       Control : in out Traverse_Control;
+       State   : in out Scan_State)
+    is
++      pragma Unreferenced (Control);
+       --  Write anything of that element that hasn't been written yet.
+    begin
+-      if Control = Terminate_Immediately then null; end if;
+-      --  The above if serves only to silence GNAT -gnatwa. 'Control' can never
+-      --  be Terminate_Immediately here!
+       Write (Element, State);
+       if not Is_Equal (State.Traverse_Top, Element) then
+          Terminate_Line (State);
+@@ -525,7 +523,7 @@
+             --  Why did I ever have the funny idea that somebody might want
+             --  a pragma index?
+             declare
+-               XRef : AD.Crossrefs.Cross_Reference :=
++               XRef : constant AD.Crossrefs.Cross_Reference :=
+                  AD.Crossrefs.Crossref_Special (Element, State.Unit);
+             begin
+                AD.Indices.Add (Element, XRef, Is_Private);
+@@ -536,7 +534,7 @@
+                     An_Enumeration_Representation_Clause |
+                     A_Record_Representation_Clause =>
+                   declare
+-                     XRef : AD.Crossrefs.Cross_Reference :=
++                     XRef : constant AD.Crossrefs.Cross_Reference :=
+                        AD.Crossrefs.Crossref_Special (Element, State.Unit);
+                   begin
+                      AD.Indices.Add (Element, XRef, Is_Private);
+@@ -851,7 +849,7 @@
+          Current : in     Natural;
+          State   : in out Scan_State)
+       is
+-         Original : Scan_State := State;
++         Original : constant Scan_State := State;
+       begin
+          AD.Printers.Open_Item
+            (State.The_Printer,
+@@ -938,7 +936,7 @@
+             return B;
+          end Unwind_Renames;
+ 
+-         Original : Scan_State := State;
++         Original : constant Scan_State := State;
+ 
+       begin
+          AD.Printers.Open_Section (State.The_Printer, Exception_Section);
+@@ -1165,7 +1163,7 @@
+ 
+       begin --  Write_Type
+          declare
+-            XRef : AD.Crossrefs.Cross_Reference :=
++            XRef : constant AD.Crossrefs.Cross_Reference :=
+               AD.Crossrefs.Crossref_Name
+                 (Get_Name (Decl), State.Unit, State.Reporter'Access);
+          begin
+@@ -1600,8 +1598,6 @@
+          Old_Indent : constant Character_Position    := State.Indent;
+          Kind       : constant AD.Printers.Item_Kind :=
+            AD.Printers.Get_Item_Kind (Items (Current).Element);
+-         use type AD.Printers.Item_Kind;
+-
+       begin
+          if Kind not in AD.Printers.Declaration_Item_Kind then
+             AD.Printers.Open_Item
+--- a/ad-user_tags.adb
++++ b/ad-user_tags.adb
+@@ -49,7 +49,6 @@
+ with GAL.Support.Hashing;
+ with GAL.ADT.Hash_Tables;
+ 
+-with Util.Environment;
+ with Util.Strings;
+ 
+ pragma Elaborate_All (GAL.ADT.Hash_Tables);
+--- a/ad-writers.adb
++++ b/ad-writers.adb
+@@ -49,16 +49,11 @@
+ with Ada.Characters.Handling;
+ with Ada.Strings.Wide_Unbounded;
+ 
+-with Asis;
+ with Asis.Elements;
+ with Asis.Exceptions;
+-with Asis.Text;
+-
+-with Asis2.Spans;
+ 
+ with AD.Crossrefs;
+ with AD.Messages.Inline;
+-with AD.Printers;
+ with AD.Text_Utilities;
+ 
+ with Util.Strings;
+@@ -246,7 +241,7 @@
+       Reporter : aliased AD.Messages.Inline.Error_Reporter :=
+         (AD.Messages.Error_Reporter with The_Printer => State.The_Printer);
+       Span : constant Asis.Text.Span      := Get_Span (Name);
+-      XRef : AD.Crossrefs.Cross_Reference :=
++      XRef : constant AD.Crossrefs.Cross_Reference :=
+         AD.Crossrefs.Crossref_Exp (Name, State.Unit, Reporter'Access);
+    begin
+       Write_Before (Span, State);
+--- a/asis2-naming.adb
++++ b/asis2-naming.adb
+@@ -285,7 +285,6 @@
+                   D := Asis2.Declarations.Enclosing_Declaration (D);
+             end case;
+          end loop;
+-         return "";
+       end Parent;
+ 
+    begin --  Container_Name;
+--- a/asis2-spans.adb
++++ b/asis2-spans.adb
+@@ -57,7 +57,6 @@
+ with Asis.Compilation_Units;
+ with Asis.Elements;
+ with Asis.Exceptions;
+-with Asis.Text;
+ 
+ with Asis2.Text;
+ 
+--- a/gal-adt-hash_tables.adb
++++ b/gal-adt-hash_tables.adb
+@@ -53,7 +53,6 @@
+ pragma License (Modified_GPL);
+ 
+ with Ada.Unchecked_Deallocation;
+-with GAL.Support.Hashing;
+ 
+ --  generic
+ --     type Key_Type (<>) is private;
+@@ -1139,10 +1138,3 @@
+    end Read;
+ 
+ end GAL.ADT.Hash_Tables;
+-
+-
+-
+-
+-
+-
+-
+--- a/util-files-text_io.adb
++++ b/util-files-text_io.adb
+@@ -44,8 +44,6 @@
+ 
+ pragma License (Modified_GPL);
+ 
+-with Util.Strings;
+-
+ package body Util.Files.Text_IO is
+ 
+    ----------------------------------------------------------------------------
+--- a/util-text.adb
++++ b/util-text.adb
+@@ -569,7 +569,7 @@
+          return 0;
+       end if;
+       declare
+-         Temporary : Unbounded_String :=
++         Temporary : constant Unbounded_String :=
+            (Ada.Finalization.Controlled with
+               Data => new String (Source.Data'Range));
+       begin
+@@ -597,7 +597,7 @@
+          raise Constraint_Error;
+       end if;
+       declare
+-         Temporary : Unbounded_String :=
++         Temporary : constant Unbounded_String :=
+            (Ada.Finalization.Controlled with
+               Data => new String (Source.Data'Range));
+       begin
diff --git a/debian/patches/series b/debian/patches/series
index b112742..982e2a8 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -2,3 +2,5 @@
 02-use-gnatgcc.patch
 fix-link-to-gpl.diff
 typo-pathes.diff
+fix-warnings.diff
+use-return-blocks.diff
diff --git a/debian/patches/use-return-blocks.diff b/debian/patches/use-return-blocks.diff
new file mode 100644
index 0000000..d03207f
--- /dev/null
+++ b/debian/patches/use-return-blocks.diff
@@ -0,0 +1,347 @@
+Description: use return blocks for local unbounded strings.
+ The return block avoids a temporary copy of a controlled object
+ during every string affectation and should enhance the efficiency.
+Author: Nicolas Boulenguez <nicolas@debian.org>
+
+--- a/util-text.adb
++++ b/util-text.adb
+@@ -232,13 +232,15 @@
+      (Left, Right : Unbounded_String)
+      return Unbounded_String
+    is
+-      Result : Unbounded_String :=
+-        (Ada.Finalization.Controlled with
+-           Data => new String (1 .. Left.Data'Last + Right.Data'Last));
+    begin
+-      Result.Data (1 .. Left.Data'Last)                    := Left.Data.all;
+-      Result.Data (Left.Data'Last + 1 .. Result.Data'Last) := Right.Data.all;
+-      return Result;
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Left.Data'Last + Right.Data'Last))
++      do
++         Result.Data (1 .. Left.Data'Last)                    := Left.Data.all;
++         Result.Data (Left.Data'Last + 1 .. Result.Data'Last) :=
++           Right.Data.all;
++      end return;
+    end "&";
+ 
+    function "&"
+@@ -247,13 +249,14 @@
+      return Unbounded_String
+    is
+       Length : constant Natural := Right'Length;
+-      Result : Unbounded_String :=
+-        (Ada.Finalization.Controlled with
+-           Data => new String (1 .. Left.Data'Last + Length));
+    begin
+-      Result.Data (1 .. Left.Data'Last)                    := Left.Data.all;
+-      Result.Data (Left.Data'Last + 1 .. Result.Data'Last) := Right;
+-      return Result;
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Left.Data'Last + Length))
++      do
++         Result.Data (1 .. Left.Data'Last)                    := Left.Data.all;
++         Result.Data (Left.Data'Last + 1 .. Result.Data'Last) := Right;
++      end return;
+    end "&";
+ 
+    function "&"
+@@ -262,13 +265,14 @@
+      return Unbounded_String
+    is
+       Length : constant Natural := Left'Length;
+-      Result : Unbounded_String :=
+-        (Ada.Finalization.Controlled with
+-           Data => new String (1 .. Length + Right.Data'Last));
+    begin
+-      Result.Data (1 .. Length)                    := Left;
+-      Result.Data (Length + 1 .. Result.Data'Last) := Right.Data.all;
+-      return Result;
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Length + Right.Data'Last))
++      do
++         Result.Data (1 .. Length)                    := Left;
++         Result.Data (Length + 1 .. Result.Data'Last) := Right.Data.all;
++      end return;
+    end "&";
+ 
+    function "&"
+@@ -276,13 +280,14 @@
+       Right : in Character)
+      return Unbounded_String
+    is
+-      Result : Unbounded_String :=
+-        (Ada.Finalization.Controlled with
+-           Data => new String (1 .. Left.Data'Last + 1));
+    begin
+-      Result.Data (1 .. Left.Data'Last) := Left.Data.all;
+-      Result.Data (Left.Data'Last + 1)  := Right;
+-      return Result;
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Left.Data'Last + 1))
++      do
++         Result.Data (1 .. Left.Data'Last) := Left.Data.all;
++         Result.Data (Left.Data'Last + 1)  := Right;
++      end return;
+    end "&";
+ 
+    function "&"
+@@ -290,13 +295,14 @@
+       Right : in Unbounded_String)
+      return Unbounded_String
+    is
+-      Result : Unbounded_String :=
+-        (Ada.Finalization.Controlled with
+-           Data => new String (1 .. Right.Data'Last + 1));
+    begin
+-      Result.Data (1)                     := Left;
+-      Result.Data (2 .. Result.Data'Last) := Right.Data.all;
+-      return Result;
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Right.Data'Last + 1))
++      do
++         Result.Data (1)                     := Left;
++         Result.Data (2 .. Result.Data'Last) := Right.Data.all;
++      end return;
+    end "&";
+ 
+    function "="
+@@ -434,13 +440,14 @@
+       Right : in Character)
+      return Unbounded_String
+    is
+-      New_String : Unbounded_String :=
+-        (Ada.Finalization.Controlled with Data => new String (1 .. Left));
+    begin
+-      for I in New_String.Data'Range loop
+-         New_String.Data (I) := Right;
+-      end loop;
+-      return New_String;
++      return New_String : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with Data => new String (1 .. Left))
++      do
++         for I in New_String.Data'Range loop
++            New_String.Data (I) := Right;
++         end loop;
++      end return;
+    end "*";
+ 
+    function "*"
+@@ -454,14 +461,16 @@
+       end if;
+       declare
+          Length     : constant Natural := Right'Last - Right'First + 1;
+-         New_String : Unbounded_String :=
+-           (Ada.Finalization.Controlled with
+-              Data => new String (1 .. Left * Length));
+       begin
+-         for I in 1 .. Left loop
+-            New_String.Data (I * Length - Length + 1 .. I * Length) := Right;
+-         end loop;
+-         return New_String;
++         return  New_String : constant Unbounded_String :=
++           (Ada.Finalization.Controlled with
++              Data => new String (1 .. Left * Length))
++         do
++            for I in 1 .. Left loop
++               New_String.Data (I * Length - Length + 1 .. I * Length) :=
++                 Right;
++            end loop;
++         end return;
+       end;
+    end "*";
+ 
+@@ -654,17 +663,15 @@
+    begin
+       Slice_Check (From, Through, Source.Data'Last);
+       if From > Through then return Source; end if;
+-      declare
+-         New_String : Unbounded_String :=
+-           (Ada.Finalization.Controlled with
+-              Data =>  new String (1 ..
+-                                   Source.Data'Last - (Through - From + 1)));
+-      begin
++      return New_String : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data =>  new String (1 ..
++                                  Source.Data'Last - (Through - From + 1)))
++      do
+          New_String.Data (1 .. From - 1) := Source.Data (1 .. From - 1);
+          New_String.Data (From .. New_String.Data'Last) :=
+            Source.Data (Through + 1 .. Source.Data'Last);
+-         return New_String;
+-      end;
++      end return;
+    end Delete;
+ 
+    --  Standard
+@@ -969,17 +976,15 @@
+       if Count <= Source.Data'Last then
+          return Slice (Source, 1, Count);
+       else
+-         declare
+-            New_String : Unbounded_String :=
+-              (Ada.Finalization.Controlled with
+-                 Data => new String (1 .. Count));
+-         begin
++         return New_String : constant Unbounded_String :=
++           (Ada.Finalization.Controlled with
++              Data => new String (1 .. Count))
++         do
+             New_String.Data (1 .. Source.Data'Last) := Source.Data.all;
+             for I in Source.Data'Last + 1 .. New_String.Data'Last loop
+                New_String.Data (I) := Pad;
+             end loop;
+-            return New_String;
+-         end;
++         end return;
+       end if;
+    end Head;
+ 
+@@ -1524,17 +1529,18 @@
+       if Position > Source.Data'Last + 1 then raise Index_Error; end if;
+       declare
+          Length     : constant Natural := New_Item'Length;
+-         New_String : Unbounded_String :=
++      begin
++         return New_String : constant Unbounded_String :=
+            (Ada.Finalization.Controlled with
+               Data => new String (1 .. Integer'Max (Source.Data'Last,
+-                                                    Position - 1 + Length)));
+-      begin
+-         New_String.Data (1 .. Position - 1) :=
+-           Source.Data (1 .. Position - 1);
+-         New_String.Data (Position .. Position + Length - 1) :=  New_Item;
+-         New_String.Data (Position + Length .. New_String.Data'Last) :=
+-           Source.Data (Position + Length .. Source.Data'Last);
+-         return New_String;
++                                                    Position - 1 + Length)))
++         do
++            New_String.Data (1 .. Position - 1) :=
++              Source.Data (1 .. Position - 1);
++            New_String.Data (Position .. Position + Length - 1) :=  New_Item;
++            New_String.Data (Position + Length .. New_String.Data'Last) :=
++              Source.Data (Position + Length .. Source.Data'Last);
++         end return;
+       end;
+    end Overwrite;
+ 
+@@ -1844,18 +1850,16 @@
+       if Count <= Source.Data'Last then
+          return Slice (Source, Source.Data'Last - Count + 1, Source.Data'Last);
+       else
+-         declare
+-            New_String : Unbounded_String :=
+-              (Ada.Finalization.Controlled with
+-                 Data => new String (1 .. Count));
+-         begin
++         return New_String : constant Unbounded_String :=
++           (Ada.Finalization.Controlled with
++              Data => new String (1 .. Count))
++         do
+             New_String.Data (New_String.Data'Last - Source.Data'Last + 1 ..
+-                             New_String.Data'Last) := Source.Data.all;
++                               New_String.Data'Last) := Source.Data.all;
+             for I in 1 .. New_String.Data'Last - Source.Data'Last loop
+                New_String.Data (I) := Pad;
+             end loop;
+-            return New_String;
+-         end;
++         end return;
+       end if;
+    end Tail;
+ 
+@@ -1946,14 +1950,15 @@
+       Mapping : in Ada.Strings.Maps.Character_Mapping)
+      return Unbounded_String
+    is
+-      Result : Unbounded_String :=
+-        (Ada.Finalization.Controlled with
+-           Data => new String (Source.Data'Range));
+    begin
+-      for I in Result.Data'Range loop
+-         Result.Data (I) := ASM.Value (Mapping, Source.Data (I));
+-      end loop;
+-      return Result;
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (Source.Data'Range))
++      do
++         for I in Result.Data'Range loop
++            Result.Data (I) := ASM.Value (Mapping, Source.Data (I));
++         end loop;
++      end return;
+    end Translate;
+ 
+    --  Standard
+@@ -1976,16 +1981,14 @@
+    begin
+       Slice_Check (From, Through, Source.Data'Last);
+       if From > Through then return Null_Unbounded_String; end if;
+-      declare
+-         Result : Unbounded_String :=
+-           (Ada.Finalization.Controlled with
+-              Data => new String (1 .. Through - From + 1));
+-      begin
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Through - From + 1))
++      do
+          for I in Result.Data'Range loop
+             Result.Data (I) := ASM.Value (Mapping, Source.Data (From + I));
+          end loop;
+-         return Result;
+-      end;
++      end return;
+    end Translate;
+ 
+    --  Slice
+@@ -2009,16 +2012,14 @@
+       use type ASM.Character_Mapping_Function;
+    begin
+       if Mapping = null then raise Constraint_Error; end if;
+-      declare
+-         Result : Unbounded_String :=
+-           (Ada.Finalization.Controlled with
+-              Data => new String (Source.Data'Range));
+-      begin
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (Source.Data'Range))
++      do
+          for I in Result.Data'Range loop
+             Result.Data (I) := Mapping (Source.Data (I));
+          end loop;
+-         return Result;
+-      end;
++      end return;
+    end Translate;
+ 
+    --  Standard
+@@ -2046,16 +2047,14 @@
+       elsif Mapping = null then
+          raise Constraint_Error;
+       end if;
+-      declare
+-         Result : Unbounded_String :=
+-           (Ada.Finalization.Controlled with
+-              Data => new String (1 .. Through - From + 1));
+-      begin
++      return Result : constant Unbounded_String :=
++        (Ada.Finalization.Controlled with
++           Data => new String (1 .. Through - From + 1))
++      do
+          for I in Result.Data'Range loop
+             Result.Data (I) := Mapping (Source.Data (From + I));
+          end loop;
+-         return Result;
+-      end;
++      end return;
+    end Translate;
+ 
+    --  Slice
-- 
2.8.1

