[Ada] Spurious warning in Containers.Bounded_Doubly_Linked_Lists

Message ID 20170912101609.GA9683@adacore.com
State New
Headers show
Series
  • [Ada] Spurious warning in Containers.Bounded_Doubly_Linked_Lists
Related show

Commit Message

Arnaud Charlet Sept. 12, 2017, 10:16 a.m.
This patch fixes a bug in which an instantiation of
Containers.Bounded_Doubly_Linked_Lists can give warnings if the actual
type passed to Element_Type is not fully default-initialized.

The following test should compile quietly.

with Ada.Containers.Bounded_Doubly_Linked_Lists;

procedure Test is
  type Async_Construct_Query_Info_T is
    record
      From_Index      : Positive;
      To_Index        : Positive;
    end record;

  package Async_Construct_Query_Info_Queue
    is new Ada.Containers.Bounded_Doubly_Linked_Lists
     (Async_Construct_Query_Info_T);
begin
  null;
end;

Tested on x86_64-pc-linux-gnu, committed on trunk

2017-09-12  Bob Duff  <duff@adacore.com>

	* libgnat/a-cbdlli.adb, libgnat/a-cbhama.adb,
	libgnat/a-cbmutr.adb, libgnat/a-cborma.adb: Rename New_Item to
	be Default_Initialized_Item, and apply pragma Unmodified to it,
	to suppress the warning.

Patch

Index: libgnat/a-cbhama.adb
===================================================================
--- libgnat/a-cbhama.adb	(revision 251998)
+++ libgnat/a-cbhama.adb	(working copy)
@@ -578,8 +578,9 @@ 
       -----------------
 
       procedure Assign_Key (Node : in out Node_Type) is
-         New_Item : Element_Type;
-         pragma Unmodified (New_Item);
+         pragma Warnings (Off);
+         Default_Initialized_Item : Element_Type;
+         pragma Unmodified (Default_Initialized_Item);
          --  Default-initialized element (ok to reference, see below)
 
       begin
@@ -591,7 +592,8 @@ 
          --  default initialization, so insert a possibly initialized element
          --  under the given key.
 
-         Node.Element := New_Item;
+         Node.Element := Default_Initialized_Item;
+         pragma Warnings (On);
       end Assign_Key;
 
       --------------
Index: libgnat/a-cborma.adb
===================================================================
--- libgnat/a-cborma.adb	(revision 251998)
+++ libgnat/a-cborma.adb	(working copy)
@@ -851,8 +851,9 @@ 
       ------------
 
       procedure Assign (Node : in out Node_Type) is
-         New_Item : Element_Type;
-         pragma Unmodified (New_Item);
+         pragma Warnings (Off);
+         Default_Initialized_Item : Element_Type;
+         pragma Unmodified (Default_Initialized_Item);
          --  Default-initialized element (ok to reference, see below)
 
       begin
@@ -863,7 +864,8 @@ 
       --  with such a scalar component or with defaulted components, so insert
       --  possibly initialized elements at the given position.
 
-         Node.Element := New_Item;
+         Node.Element := Default_Initialized_Item;
+         pragma Warnings (On);
       end Assign;
 
       --------------
Index: libgnat/a-cbdlli.adb
===================================================================
--- libgnat/a-cbdlli.adb	(revision 251998)
+++ libgnat/a-cbdlli.adb	(working copy)
@@ -1016,9 +1016,13 @@ 
       Count     : Count_Type := 1)
    is
       pragma Warnings (Off);
-      New_Item : Element_Type;
+      Default_Initialized_Item : Element_Type;
+      pragma Unmodified (Default_Initialized_Item);
       --  OK to reference, see below. Note that we need to suppress both the
-      --  front end warning and the back end warning.
+      --  front end warning and the back end warning. In addition, pragma
+      --  Unmodified is needed to suppress the warning ``actual type for
+      --  "Element_Type" should be fully initialized type'' on certain
+      --  instantiations.
 
    begin
       --  There is no explicit element provided, but in an instance the element
@@ -1027,7 +1031,7 @@ 
       --  initialization, so insert the specified number of possibly
       --  initialized elements at the given position.
 
-      Insert (Container, Before, New_Item, Position, Count);
+      Insert (Container, Before, Default_Initialized_Item, Position, Count);
       pragma Warnings (On);
    end Insert;
 
Index: libgnat/a-cbmutr.adb
===================================================================
--- libgnat/a-cbmutr.adb	(revision 251998)
+++ libgnat/a-cbmutr.adb	(working copy)
@@ -1581,8 +1581,9 @@ 
       First : Count_Type;
       Last  : Count_Type;
 
-      New_Item : Element_Type;
-      pragma Unmodified (New_Item);
+      pragma Warnings (Off);
+      Default_Initialized_Item : Element_Type;
+      pragma Unmodified (Default_Initialized_Item);
       --  OK to reference, see below
 
    begin
@@ -1629,12 +1630,13 @@ 
       --  initialization, so insert the specified number of possibly
       --  initialized elements at the given position.
 
-      Allocate_Node (Container, New_Item, First);
+      Allocate_Node (Container, Default_Initialized_Item, First);
       Nodes (First).Parent := Parent.Node;
 
       Last := First;
       for J in Count_Type'(2) .. Count loop
-         Allocate_Node (Container, New_Item, Nodes (Last).Next);
+         Allocate_Node
+           (Container, Default_Initialized_Item, Nodes (Last).Next);
          Nodes (Nodes (Last).Next).Parent := Parent.Node;
          Nodes (Nodes (Last).Next).Prev := Last;
 
@@ -1651,6 +1653,7 @@ 
       Container.Count := Container.Count + Count;
 
       Position := Cursor'(Parent.Container, First);
+      pragma Warnings (On);
    end Insert_Child;
 
    -------------------------