.. index:: No_Default_Initialization
[GNAT] This restriction prohibits any instance of default initialization
-of variables. The binder implements a consistency rule which prevents
-any unit compiled without the restriction from with'ing a unit with the
+of variables or components. The binder implements a consistency check that
+prevents any unit without the restriction from with'ing a unit with the
restriction (this allows the generation of initialization procedures to
be skipped, since you can be sure that no call is ever generated to an
initialization procedure in a unit with the restriction active). If used
-- object creation that will invoke it otherwise.
else
- if Present (Base_Init_Proc (Base_Type (Ctype)))
- or else Has_Task (Base_Type (Ctype))
- then
- Append_List_To (Stmts,
- Build_Initialization_Call (N,
- Id_Ref => Indexed_Comp,
- Typ => Ctype,
- With_Default_Init => True));
+ if Present (Base_Init_Proc (Ctype)) then
+ Check_Restriction (No_Default_Initialization, N);
+
+ if not Restriction_Active (No_Default_Initialization) then
+ Append_List_To (Stmts,
+ Build_Initialization_Call (N,
+ Id_Ref => Indexed_Comp,
+ Typ => Ctype,
+ With_Default_Init => True));
+ end if;
-- If the component type has invariants, add an invariant
-- check after the component is default-initialized. It will
elsif Box_Present (Comp)
and then Has_Non_Null_Base_Init_Proc (Etype (Selector))
then
+ Check_Restriction (No_Default_Initialization, N);
+
if Ekind (Selector) /= E_Discriminant then
Generate_Finalization_Actions;
end if;
end if;
end;
- Append_List_To (L,
- Build_Initialization_Call (N,
- Id_Ref => Make_Selected_Component (Loc,
- Prefix => New_Copy_Tree (Target),
- Selector_Name =>
- New_Occurrence_Of (Selector, Loc)),
- Typ => Etype (Selector),
- Enclos_Type => Typ,
- With_Default_Init => True));
+ if not Restriction_Active (No_Default_Initialization) then
+ Append_List_To (L,
+ Build_Initialization_Call (N,
+ Id_Ref => Make_Selected_Component (Loc,
+ Prefix =>
+ New_Copy_Tree (Target),
+ Selector_Name =>
+ New_Occurrence_Of (Selector, Loc)),
+ Typ => Etype (Selector),
+ Enclos_Type => Typ,
+ With_Default_Init => True));
+ end if;
-- Prepare for component assignment
@copying
@quotation
-GNAT Reference Manual , Jun 24, 2024
+GNAT Reference Manual , Jun 27, 2024
AdaCore
@geindex No_Default_Initialization
[GNAT] This restriction prohibits any instance of default initialization
-of variables. The binder implements a consistency rule which prevents
-any unit compiled without the restriction from with’ing a unit with the
+of variables or components. The binder implements a consistency check that
+prevents any unit without the restriction from with’ing a unit with the
restriction (this allows the generation of initialization procedures to
be skipped, since you can be sure that no call is ever generated to an
initialization procedure in a unit with the restriction active). If used