sem_ch3.adb (Analyze_Subtype_Declaration): if an incomplete type is tagged, so is...
authorEd Schonberg <schonberg@adacore.com>
Tue, 12 Jun 2012 10:34:33 +0000 (10:34 +0000)
committerArnaud Charlet <charlet@gcc.gnu.org>
Tue, 12 Jun 2012 10:34:33 +0000 (12:34 +0200)
2012-06-12  Ed Schonberg  <schonberg@adacore.com>

* sem_ch3.adb (Analyze_Subtype_Declaration): if an incomplete
type is tagged, so is a subtype of it.
* sem_ch12.adb (Validate_Actual_Subprogram): implement AI05-0296,
concerning freeze rules in the presence of formal incomplete
types: a formal abstract subprogram cannot have an incomplete
controlling type, and the profile of the actual subprogram does
not freeze if it includes an incomplete untagged type.

From-SVN: r188442

gcc/ada/ChangeLog
gcc/ada/sem_ch12.adb
gcc/ada/sem_ch3.adb

index 4f6782225e9a6e8d70a62a74da0ccd82221780fc..6da4ac62251ecb63b476d1f8566012a00ba279ea 100644 (file)
@@ -1,3 +1,13 @@
+2012-06-12  Ed Schonberg  <schonberg@adacore.com>
+
+       * sem_ch3.adb (Analyze_Subtype_Declaration): if an incomplete
+       type is tagged, so is a subtype of it.
+       * sem_ch12.adb (Validate_Actual_Subprogram): implement AI05-0296,
+       concerning freeze rules in the presence of formal incomplete
+       types: a formal abstract subprogram cannot have an incomplete
+       controlling type, and the profile of the actual subprogram does
+       not freeze if it includes an incomplete untagged type.
+
 2012-06-12  Robert Dewar  <dewar@adacore.com>
 
        * a-direct.adb: Minor reformatting.
index d38d2e277ddd2c880026050901d363e2dfd2134e..4bb7cee6a1dae780e92a1a8af4967ea8f87c587c 100644 (file)
@@ -2664,6 +2664,14 @@ package body Sem_Ch12 is
                Error_Msg_N
                  ("abstract formal subprogram must have a controlling type",
                   N);
+
+            elsif Ada_Version >= Ada_2012
+              and then Is_Incomplete_Type (Ctrl_Type)
+            then
+               Error_Msg_NE
+                 ("controlling type of abstract formal subprogram cannot " &
+                     "be incomplete type", N, Ctrl_Type);
+
             else
                Check_Controlling_Formals (Ctrl_Type, Nam);
             end if;
@@ -9411,6 +9419,59 @@ package body Sem_Ch12 is
          end;
       end if;
 
+      --  In Ada 2012, enforce the (RM 13.14(10.2/3)) freezing rule concerning
+      --  formal incomplete types: a callable entity freezes its profile,
+      --  unless it has an incomplete untagged formal.
+
+      if Ada_Version >= Ada_2012 then
+         declare
+            F : Entity_Id;
+            Has_Untagged_Inc : Boolean;
+
+         begin
+            F := First_Formal (Analyzed_S);
+            Has_Untagged_Inc := False;
+            while Present (F) loop
+               if Ekind (Etype (F)) = E_Incomplete_Type
+                 and then not Is_Tagged_Type (Etype (F))
+               then
+                  Has_Untagged_Inc := True;
+                  exit;
+               end if;
+
+               F := Next_Formal (F);
+            end loop;
+
+            if Ekind (Analyzed_S) = E_Function
+              and then Ekind (Etype (Analyzed_S)) = E_Incomplete_Type
+              and then not Is_Tagged_Type (Etype (F))
+            then
+               Has_Untagged_Inc := True;
+            end if;
+
+            if Is_Entity_Name (Actual)
+              and then not Has_Untagged_Inc
+            then
+               F := First_Formal (Entity (Actual));
+               while Present (F) loop
+                  Freeze_Before (Instantiation_Node, Etype (F));
+
+                  if Is_Incomplete_Or_Private_Type (Etype (F))
+                    and then No (Full_View (Etype (F)))
+                    and then not Is_Generic_Type (Etype (F))
+                  then
+                     Error_Msg_NE
+                       ("type& must be frozen before this point",
+                          Instantiation_Node, Etype (F));
+                     Abandon_Instantiation (Instantiation_Node);
+                  end if;
+
+                  F := Next_Formal (F);
+               end loop;
+            end if;
+         end;
+      end if;
+
       return Decl_Node;
    end Instantiate_Formal_Subprogram;
 
index e6f3c4c7c9bf203738564978de3f517d4592a605..1fdf17eca7c538b21ecf3ff310ceb3df6a6e6797 100644 (file)
@@ -4340,11 +4340,15 @@ package body Sem_Ch3 is
 
             when E_Incomplete_Type =>
                if Ada_Version >= Ada_2005 then
-                  Set_Ekind (Id, E_Incomplete_Subtype);
 
-                  --  Ada 2005 (AI-412): Decorate an incomplete subtype
-                  --  of an incomplete type visible through a limited
-                  --  with clause.
+                  --  A subtype of an incomplete type can be explicitly tagged
+
+                  Set_Ekind              (Id, E_Incomplete_Subtype);
+                  Set_Is_Tagged_Type     (Id, Is_Tagged_Type (T));
+                  Set_Private_Dependents (Id, New_Elmt_List);
+
+                  --  Ada 2005 (AI-412): Decorate an incomplete subtype of an
+                  --  incomplete type visible through a limited with clause.
 
                   if From_With_Type (T)
                     and then Present (Non_Limited_View (T))