This switch activates warnings for access to variables which
may not be properly initialized. The default is that
- such warnings are generated.
+ such warnings are generated. This switch will also be emitted when
+ initializing an array or record object via the following aggregate:
+ .. code-block:: ada
+
+ Array_Or_Record : XXX := (others => <>);
+
+ unless the relevant type fully initializes all components.
.. index:: -gnatwV (gcc)
This switch suppresses warnings for access to variables which
may not be properly initialized.
- For variables of a composite type, the warning can also be suppressed in
- Ada 2005 by using a default initialization with a box. For example, if
- Table is an array of records whose components are only partially uninitialized,
- then the following code:
-
- .. code-block:: ada
-
- Tab : Table := (others => <>);
-
- will suppress warnings on subsequent statements that access components
- of variable Tab.
.. index:: -gnatw.v (gcc)
This switch activates warnings for access to variables which
may not be properly initialized. The default is that
-such warnings are generated.
+such warnings are generated. This switch will also be emitted when
+initializing an array or record object via the following aggregate:
+
+@example
+Array_Or_Record : XXX := (others => <>);
+@end example
+
+unless the relevant type fully initializes all components.
@end table
@geindex -gnatwV (gcc)
This switch suppresses warnings for access to variables which
may not be properly initialized.
-For variables of a composite type, the warning can also be suppressed in
-Ada 2005 by using a default initialization with a box. For example, if
-Table is an array of records whose components are only partially uninitialized,
-then the following code:
-
-@example
-Tab : Table := (others => <>);
-@end example
-
-will suppress warnings on subsequent statements that access components
-of variable Tab.
@end table
@geindex -gnatw.v (gcc)
type Node_Array is array (Count_Type range <>) of Node_Type;
type List (Capacity : Count_Type) is tagged record
- Nodes : Node_Array (1 .. Capacity) := (others => <>);
+ Nodes : Node_Array (1 .. Capacity);
Free : Count_Type'Base := -1;
First : Count_Type := 0;
Last : Count_Type := 0;
type Element_Array is array (Count_Type range <>) of aliased Element_Type;
type Tree (Capacity : Count_Type) is tagged record
- Nodes : Tree_Node_Array (0 .. Capacity) := (others => <>);
- Elements : Element_Array (1 .. Capacity) := (others => <>);
+ Nodes : Tree_Node_Array (0 .. Capacity);
+ Elements : Element_Array (1 .. Capacity);
Free : Count_Type'Base := No_Node;
TC : aliased Tamper_Counts;
Count : Count_Type := 0;
First, Last : Count_Type := 0;
Length : Count_Type := 0;
Max_Length : Count_Type := 0;
- Elements : Element_Array (1 .. Capacity) := (others => <>);
+ Elements : Element_Array (1 .. Capacity);
end record;
end Implementation;
Length : Count_Type := 0;
First : Count_Type := 0;
Last : Count_Type := 0;
- Nodes : Node_Array (1 .. Capacity) := (others => <>);
+ Nodes : Node_Array (1 .. Capacity);
end record;
Empty_List : constant List := (0, others => <>);
function "=" (L, R : Elements_Array) return Boolean is abstract;
type Vector (Capacity : Count_Type) is tagged record
- Elements : Elements_Array (1 .. Capacity) := (others => <>);
+ Elements : Elements_Array (1 .. Capacity);
Last : Extended_Index := No_Index;
TC : aliased Tamper_Counts;
end record with Put_Image => Put_Image;
Length : Count_Type := 0;
TC : aliased Helpers.Tamper_Counts;
Free : Count_Type'Base := -1;
- Nodes : Nodes_Type (1 .. Capacity) := (others => <>);
+ Nodes : Nodes_Type (1 .. Capacity);
Buckets : Buckets_Type (1 .. Modulus) := (others => 0);
end record;
-- 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.
+ -- its own initialization expression.
type Tree_Type (Capacity : Count_Type) is tagged record
First : Count_Type := 0;
Length : Count_Type := 0;
TC : aliased Helpers.Tamper_Counts;
Free : Count_Type'Base := -1;
- Nodes : Nodes_Type (1 .. Capacity) := (others => <>);
+ Nodes : Nodes_Type (1 .. Capacity);
end record;
package Implementation is new Helpers.Generic_Implementation;
type Node_Array is array (Count_Type range <>) of Node_Type;
type List (Capacity : Count_Type) is tagged limited record
- Nodes : Node_Array (1 .. Capacity) := (others => <>);
+ Nodes : Node_Array (1 .. Capacity);
Free : Count_Type'Base := -1;
First : Count_Type := 0;
Last : Count_Type := 0;
pragma Stream_Convert (Exception_Occurrence, String_To_EO, EO_To_String);
-- Functions for implementing Exception_Occurrence stream attributes
+ pragma Warnings (Off, "aggregate not fully initialized");
Null_Occurrence : constant Exception_Occurrence := (others => <>);
+ pragma Warnings (On, "aggregate not fully initialized");
end Ada.Exceptions;
EA : Stream_Element_Array (1 .. Last);
end record;
- Empty_Elements : aliased Elements_Type := (Last => 0, EA => (others => <>));
+ Empty_Elements : aliased Elements_Type (0);
type Elements_Access is access all Elements_Type;
-- HMAC key
end record;
+ pragma Warnings (Off, "aggregate not fully initialized");
Initial_Context : constant Context (KL => 0) := (others => <>);
+ pragma Warnings (On, "aggregate not fully initialized");
-- Initial values are provided by default initialization of Context
type Hash_Stream (C : access Context) is
-- The actual aggregate subtype. This is not necessarily the same as Typ
-- which is the subtype of the context in which the aggregate was found.
+ Others_Box : Boolean := False;
+ -- Set to True if N represents a simple aggregate with only
+ -- (others => <>), not nested as part of another aggregate.
+
+ function Within_Aggregate (N : Node_Id) return Boolean;
+ -- Return True if N is part of an N_Aggregate
+
+ ----------------------
+ -- Within_Aggregate --
+ ----------------------
+
+ function Within_Aggregate (N : Node_Id) return Boolean is
+ P : Node_Id := Parent (N);
+ begin
+ while Present (P) loop
+ if Nkind (P) = N_Aggregate then
+ return True;
+ end if;
+
+ P := Parent (P);
+ end loop;
+
+ return False;
+ end Within_Aggregate;
+
begin
-- Ignore junk empty aggregate resulting from parser error
and then Present (Component_Associations (N))
then
declare
- Comp : Node_Id;
+ Comp : Node_Id;
+ First_Comp : Boolean := True;
begin
Comp := First (Component_Associations (N));
while Present (Comp) loop
if Box_Present (Comp) then
+ if First_Comp
+ and then No (Expressions (N))
+ and then Nkind (First (Choices (Comp))) = N_Others_Choice
+ and then not Within_Aggregate (N)
+ then
+ Others_Box := True;
+ end if;
+
Insert_Actions (N, Freeze_Entity (Typ, N));
exit;
end if;
+ First_Comp := False;
Next (Comp);
end loop;
end;
Set_Analyzed (N);
end if;
+ if Warn_On_No_Value_Assigned
+ and then Others_Box
+ and then not Is_Fully_Initialized_Type (Etype (N))
+ then
+ Error_Msg_N ("?v?aggregate not fully initialized", N);
+ end if;
+
Check_Function_Writable_Actuals (N);
end Resolve_Aggregate;
-- Returns True is aggregate Aggr consists of a single OTHERS choice
function Is_Single_Aggregate (Aggr : Node_Id) return Boolean;
- -- Returns True is aggregate Aggr consists of a single choice
+ -- Returns True if aggregate Aggr consists of a single choice
-- WARNING: There is a matching C declaration of this subprogram in fe.h
elsif Nkind (N) = N_Attribute_Reference then
Error_Msg_NE
("Access attribute of & before body seen<<", N, Orig_Ent);
- Error_Msg_N ("\possible Program_Error on later references<", N);
+ Error_Msg_N
+ ("\possible Program_Error on later references<<", N);
Insert_Check := False;
elsif Nkind (Unit_Declaration_Node (Orig_Ent)) /=
N_Subprogram_Renaming_Declaration
+ or else Is_Generic_Actual_Subprogram (Orig_Ent)
then
Error_Msg_NE
("cannot call& before body seen<<", N, Orig_Ent);
-
- elsif not Is_Generic_Actual_Subprogram (Orig_Ent) then
+ else
Insert_Check := False;
end if;
-- types.
if Is_By_Reference_Type (Etype (F))
- or else Is_By_Reference_Type (Expr_Typ)
+ or else Is_By_Reference_Type (Expr_Typ)
then
Error_Msg_N
("view conversion between unrelated by reference "
- & "array types not allowed (\'A'I-00246)", A);
+ & "array types not allowed ('A'I-00246)", A);
-- In Ada 2005 mode, check view conversion component
-- type cannot be private, tagged, or volatile. Note
and then not Warnings_Off_E1
and then not Has_Junk_Name (E1)
then
- Output_Reference_Error
- ("?v?variable& is read but never assigned!");
+ if Is_Access_Type (E1T)
+ or else
+ not Is_Partially_Initialized_Type (E1T, False)
+ then
+ Output_Reference_Error
+ ("?v?variable& is read but never assigned!");
+ end if;
+
May_Need_Initialized_Actual (E1);
end if;
procedure Proc is
R : Rec;
begin
- R := (others => <>);
+ R := (others => <>); -- { dg-warning "aggregate not fully initialized" }
end;
end Opt11;