When manipulating bounded tree-based container objects, that do not otherwise
have any explicit initialization expression, the compiler would emit a warning
about the object not being initialized, because the Nodes component of the tree
type had not been given an initialization expression.

This warning is a false positive, because the logical state of the object is
empty, and other components of the tree record type are initialized, in a
manner that establishes the representation invariant of the object.

In order to eliminate the warning, the Nodes component of the tree type was
given an initialization expression.

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

2011-08-31  Matthew Heaney  <hea...@adacore.com>

        * a-crbltr.ads (Tree_Type): Default-initialize the Nodes component.

Index: a-crbltr.ads
===================================================================
--- a-crbltr.ads        (revision 178358)
+++ a-crbltr.ads        (working copy)
@@ -6,7 +6,7 @@
 --                                                                          --
 --                                 S p e c                                  --
 --                                                                          --
---          Copyright (C) 2004-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 2004-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -53,6 +53,13 @@
    package Generic_Bounded_Tree_Types is
       type Nodes_Type is array (Count_Type range <>) of Node_Type;
 
+      --  Note that objects of type Tree_Type are logically initialized (in the
+      --  sense that representation invariants of type are satisfied by dint of
+      --  default initialization), even without the Nodes component also having
+      --  its own initialization expression. We only initializae the Nodes
+      --  component here in order to prevent spurious compiler warnings about
+      --  the container object not being fully initialized.
+
       type Tree_Type (Capacity : Count_Type) is tagged record
          First  : Count_Type := 0;
          Last   : Count_Type := 0;
@@ -61,7 +68,7 @@
          Busy   : Natural := 0;
          Lock   : Natural := 0;
          Free   : Count_Type'Base := -1;
-         Nodes  : Nodes_Type (1 .. Capacity);
+         Nodes  : Nodes_Type (1 .. Capacity) := (others => <>);
       end record;
    end Generic_Bounded_Tree_Types;
 

Reply via email to