This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH] ada/22387: Initialize the Corresponding_Discriminant when present


> No, this can only be done within an initialization procedure. The  
> predicate to use is Inside_Init_Proc. This has been fixed in GNAT,  
> and the patch will eventually be propagated to the trunk.  In any  
> case, many thanks for spotting the problem.

Here is Ed's correct patch. Feel free to apply it to trunk, otherwise
I'll commit it in a few days.

	* exp_ch5.adb (Expand_Assign_Record): Within an initialization
	procedure for a derived type retrieve the discriminant values from
	the parent using the corresponding discriminant.

Arno
--
--- exp_ch5.adb 2008/04/15 14:42:10     1.416
+++ exp_ch5.adb 2008/04/15 17:06:37     1.417
@@ -1345,13 +1345,30 @@ package body Exp_Ch5 is
             F := First_Discriminant (R_Typ);
             while Present (F) loop

-               if Is_Unchecked_Union (Base_Type (R_Typ)) then
-                  Insert_Action (N, Make_Field_Assign (F, True));
-               else
-                  Insert_Action (N, Make_Field_Assign (F));
-               end if;
+               --  If we are expanding the initialization of a derived record
+               --  that constrains or renames discriminants of the parent, we
+               --  must use the corresponding discriminant in the parent.
+
+               declare
+                  CF : Entity_Id;

-               Next_Discriminant (F);
+               begin
+                  if Inside_Init_Proc
+                    and then Present (Corresponding_Discriminant (F))
+                  then
+                     CF := Corresponding_Discriminant (F);
+                  else
+                     CF := F;
+                  end if;
+
+                  if Is_Unchecked_Union (Base_Type (R_Typ)) then
+                     Insert_Action (N, Make_Field_Assign (CF, True));
+                  else
+                     Insert_Action (N, Make_Field_Assign (CF));
+                  end if;
+
+                  Next_Discriminant (F);
+               end;
             end loop;
          end if;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]