From: squirek <squi...@adacore.com>

This patch fixes an issue in the compiler whereby instantiating Multiway_Trees
with a formal type leads to a compile-time error due to the expression supplied
for aspect Disable_Controlled specified on types decalred within
Multiway_Trees' body not being static.

gcc/ada/ChangeLog:

        * libgnat/a-comutr.adb, libgnat/a-comutr.ads:
        Move the declarations of iterator types into the specification and
        add additional comments.

Tested on x86_64-pc-linux-gnu, committed on master.

---
 gcc/ada/libgnat/a-comutr.adb | 49 ------------------------------------
 gcc/ada/libgnat/a-comutr.ads | 39 ++++++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 49 deletions(-)

diff --git a/gcc/ada/libgnat/a-comutr.adb b/gcc/ada/libgnat/a-comutr.adb
index e866e2ff895..df3741bbbb0 100644
--- a/gcc/ada/libgnat/a-comutr.adb
+++ b/gcc/ada/libgnat/a-comutr.adb
@@ -41,55 +41,6 @@ is
    pragma Warnings (Off, "variable ""Lock*"" is not referenced");
    --  See comment in Ada.Containers.Helpers
 
-   --------------------
-   --  Root_Iterator --
-   --------------------
-
-   type Root_Iterator is abstract new Limited_Controlled and
-     Tree_Iterator_Interfaces.Forward_Iterator with
-   record
-      Container : Tree_Access;
-      Subtree   : Tree_Node_Access;
-   end record
-     with Disable_Controlled => not T_Check;
-
-   overriding procedure Finalize (Object : in out Root_Iterator);
-
-   -----------------------
-   --  Subtree_Iterator --
-   -----------------------
-
-   --  ??? these headers are a bit odd, but for sure they do not substitute
-   --  for documenting things, what *is* a Subtree_Iterator?
-
-   type Subtree_Iterator is new Root_Iterator with null record;
-
-   overriding function First (Object : Subtree_Iterator) return Cursor;
-
-   overriding function Next
-     (Object   : Subtree_Iterator;
-      Position : Cursor) return Cursor;
-
-   ---------------------
-   --  Child_Iterator --
-   ---------------------
-
-   type Child_Iterator is new Root_Iterator and
-     Tree_Iterator_Interfaces.Reversible_Iterator with null record
-       with Disable_Controlled => not T_Check;
-
-   overriding function First (Object : Child_Iterator) return Cursor;
-
-   overriding function Next
-     (Object   : Child_Iterator;
-      Position : Cursor) return Cursor;
-
-   overriding function Last (Object : Child_Iterator) return Cursor;
-
-   overriding function Previous
-     (Object   : Child_Iterator;
-      Position : Cursor) return Cursor;
-
    -----------------------
    -- Local Subprograms --
    -----------------------
diff --git a/gcc/ada/libgnat/a-comutr.ads b/gcc/ada/libgnat/a-comutr.ads
index b6d006fd626..adc2cad8e5e 100644
--- a/gcc/ada/libgnat/a-comutr.ads
+++ b/gcc/ada/libgnat/a-comutr.ads
@@ -491,6 +491,45 @@ private
 
    for Reference_Type'Write use Write;
 
+   --  Base iterator type for shared functionality between Child_Iterator
+   --  and Subtree_Iterator - namely finalization.
+   type Root_Iterator is abstract new Limited_Controlled and
+     Tree_Iterator_Interfaces.Forward_Iterator with
+   record
+      Container : Tree_Access;
+      Subtree   : Tree_Node_Access;
+   end record
+     with Disable_Controlled => not T_Check;
+
+   overriding procedure Finalize (Object : in out Root_Iterator);
+
+   --  Iterator to handle traversal within a specific subtree.
+   type Subtree_Iterator is new Root_Iterator with null record;
+
+   overriding function First (Object : Subtree_Iterator) return Cursor;
+
+   overriding function Next
+     (Object   : Subtree_Iterator;
+      Position : Cursor) return Cursor;
+
+   --  Iterator to handle bidirectional traversal of a node's immediate
+   --  children for operations like reverse enumeration and selective
+   --  insertion.
+   type Child_Iterator is new Root_Iterator and
+     Tree_Iterator_Interfaces.Reversible_Iterator with null record
+       with Disable_Controlled => not T_Check;
+
+   overriding function First (Object : Child_Iterator) return Cursor;
+
+   overriding function Next
+     (Object   : Child_Iterator;
+      Position : Cursor) return Cursor;
+
+   overriding function Last (Object : Child_Iterator) return Cursor;
+
+   overriding function Previous
+     (Object   : Child_Iterator;
+      Position : Cursor) return Cursor;
    --  See Ada.Containers.Vectors for documentation on the following
 
    function Pseudo_Reference
-- 
2.43.0

Reply via email to