[Ada] Remove spurious warning on access discriminant
Arnaud Charlet
charlet@adacore.com
Tue Aug 5 08:22:00 GMT 2008
The generated default stream input function for a record type includes
individual declarations for each discriminant and each component, followed
by a call to the corresponding input function for the component type. If the
type is a null-excluding access type we must mark the corresponding declration
as needing no initialization, to prevent spurious warnings. This mark was
present for components, but missing for access discriminants.
See gnat.dg/access_discr2.adb
Tested on i686-pc-linux-gnu, committed on trunk
2008-08-05 Ed Schonberg <schonberg@adacore.com>
* exp_strm.adb (Build_Record_Or_Elementary_Input_Function): For access
discriminants, indicate that the corresponding object declaration has
no initialization, to prevent spurious warnings when the access type is
null-excluding.
-------------- next part --------------
Index: exp_strm.adb
===================================================================
--- exp_strm.adb (revision 138518)
+++ exp_strm.adb (working copy)
@@ -1113,12 +1113,22 @@ package body Exp_Strm is
while Present (Discr) loop
Cn := New_External_Name ('C', J);
- Append_To (Decls,
+ Decl :=
Make_Object_Declaration (Loc,
Defining_Identifier => Make_Defining_Identifier (Loc, Cn),
Object_Definition =>
- New_Occurrence_Of (Etype (Discr), Loc)));
+ New_Occurrence_Of (Etype (Discr), Loc));
+
+ -- If the this is an access discriminant, do not perform default
+ -- initialization. The discriminant is about to get its value
+ -- from Read, and if the type is null excluding we do not want
+ -- spurious warnings on an initial null.
+
+ if Is_Access_Type (Etype (Discr)) then
+ Set_No_Initialization (Decl);
+ end if;
+ Append_To (Decls, Decl);
Append_To (Decls,
Make_Attribute_Reference (Loc,
Prefix => New_Occurrence_Of (Etype (Discr), Loc),
More information about the Gcc-patches
mailing list