OSDN Git Service

2008-05-26 Gary Dismukes <dismukes@adacore.com>
authorcharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 26 May 2008 15:50:54 +0000 (15:50 +0000)
committercharlet <charlet@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 26 May 2008 15:50:54 +0000 (15:50 +0000)
* exp_ch3.adb (Expand_N_Object_Declaration): Remove checks for
No_Default_Initialization, which is now delayed until the freeze point
of the object. Add a comment about deferral of the check.

* freeze.adb (Freeze_Entity): The check for No_Default_Initialization
on objects is moved here.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@135941 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ada/exp_ch3.adb
gcc/ada/freeze.adb

index 8324763..71f09e4 100644 (file)
@@ -4278,7 +4278,11 @@ package body Exp_Ch3 is
 
             and then not Suppress_Init_Proc (Typ)
          then
-            Check_Restriction (No_Default_Initialization, N);
+            --  Return without initializing when No_Default_Initialization
+            --  applies. Note that the actual restriction check occurs later,
+            --  when the object is frozen, because we don't know yet whether
+            --  the object is imported, which is a case where the check does
+            --  not apply.
 
             if Restriction_Active (No_Default_Initialization) then
                return;
@@ -4324,7 +4328,6 @@ package body Exp_Ch3 is
            and then not Is_Internal (Def_Id)
            and then not Has_Init_Expression (N)
          then
-            Check_Restriction (No_Default_Initialization, N);
             Set_No_Initialization (N, False);
             Set_Expression (N, Get_Simple_Init_Val (Typ, N, Esize (Def_Id)));
             Analyze_And_Resolve (Expression (N), Typ);
index bf4f946..31f9398 100644 (file)
@@ -29,6 +29,7 @@ with Debug;    use Debug;
 with Einfo;    use Einfo;
 with Elists;   use Elists;
 with Errout;   use Errout;
+with Exp_Ch3;  use Exp_Ch3;
 with Exp_Ch7;  use Exp_Ch7;
 with Exp_Disp; use Exp_Disp;
 with Exp_Pakd; use Exp_Pakd;
@@ -2651,10 +2652,31 @@ package body Freeze is
 
                Validate_Object_Declaration (Declaration_Node (E));
 
-               --  If there is an address clause, check it is valid
+               --  If there is an address clause, check that it is valid
 
                Check_Address_Clause (E);
 
+               --  If the object needs any kind of default initialization, an
+               --  error must be issued if No_Default_Initialization applies.
+               --  The check doesn't apply to imported objects, which are not
+               --  ever default initialized, and is why the check is deferred
+               --  until freezing, at which point we know if Import applies.
+
+               if not Is_Imported (E)
+                 and then not Has_Init_Expression (Declaration_Node (E))
+                 and then
+                   ((Has_Non_Null_Base_Init_Proc (Etype (E))
+                      and then not No_Initialization (Declaration_Node (E))
+                      and then not Is_Value_Type (Etype (E))
+                      and then not Suppress_Init_Proc (Etype (E)))
+                    or else
+                      (Needs_Simple_Initialization (Etype (E))
+                        and then not Is_Internal (E)))
+               then
+                  Check_Restriction
+                    (No_Default_Initialization, Declaration_Node (E));
+               end if;
+
                --  For imported objects, set Is_Public unless there is also an
                --  address clause, which means that there is no external symbol
                --  needed for the Import (Is_Public may still be set for other