OSDN Git Service

2010-06-22 Robert Dewar <dewar@adacore.com>
[pf3gnuchains/gcc-fork.git] / gcc / ada / sem_ch12.adb
index cfb08c8..1f28f9d 100644 (file)
@@ -2598,7 +2598,7 @@ package body Sem_Ch12 is
          then
             Error_Msg_N ("premature usage of incomplete type", Def);
 
-         elsif Is_Internal (Designated_Type (T)) then
+         elsif not Is_Entity_Name (Subtype_Indication (Def)) then
             Error_Msg_N
               ("only a subtype mark is allowed in a formal", Def);
          end if;
@@ -10396,6 +10396,7 @@ package body Sem_Ch12 is
    procedure Mark_Context (Inst_Decl : Node_Id; Gen_Decl : Node_Id) is
       Inst_CU : constant Unit_Number_Type := Get_Code_Unit   (Inst_Decl);
       Gen_CU  : constant Unit_Number_Type := Get_Source_Unit (Gen_Decl);
+      Inst    : Entity_Id := Cunit_Entity (Inst_CU);
       Clause  : Node_Id;
 
    begin
@@ -10410,10 +10411,31 @@ package body Sem_Ch12 is
            and then  Library_Unit (Clause) = Cunit (Gen_CU)
          then
             Set_Withed_Body (Clause, Cunit (Gen_CU));
+            return;
          end if;
 
          Next (Clause);
       end loop;
+
+      --  If the with-clause for the generic unit was not found, it must
+      --  appear in some ancestor of the current unit.
+
+      while Is_Child_Unit (Inst) loop
+         Inst := Scope (Inst);
+         Clause :=
+           First (Context_Items (Parent (Unit_Declaration_Node (Inst))));
+
+         while Present (Clause) loop
+            if Nkind (Clause) = N_With_Clause
+              and then  Library_Unit (Clause) = Cunit (Gen_CU)
+            then
+               Set_Withed_Body (Clause, Cunit (Gen_CU));
+               return;
+            end if;
+
+            Next (Clause);
+         end loop;
+      end loop;
    end Mark_Context;
 
    ---------------------