sem_ch8.adb (Analyze_Subprogram_Renaming): When renaming an attribute as a actual...
authorEd Schonberg <schonberg@adacore.com>
Wed, 30 Jul 2008 15:52:58 +0000 (17:52 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Wed, 30 Jul 2008 15:52:58 +0000 (17:52 +0200)
2008-07-30  Ed Schonberg  <schonberg@adacore.com>

* sem_ch8.adb (Analyze_Subprogram_Renaming): When renaming an attribute
as a actual in an instance, check for a missing attribute to prevent
program_error on an illegal program.

* exp_util.adb (Find_Prim_Op): Rather than Assert (False), raise program
error if primitive is not found, so that exception can be handled
elsewhere on illegal programs.

From-SVN: r138322

gcc/ada/exp_util.adb
gcc/ada/sem_ch8.adb

index d41a6bc383c1ba2a22ee50eeabeec2032c573d04..e4b4389618b19f23f92fd811d1016878c3bd49b1 100644 (file)
@@ -1581,7 +1581,10 @@ package body Exp_Util is
                 or else Etype (First_Entity (Op)) = Etype (Last_Entity (Op)));
 
          Next_Elmt (Prim);
-         pragma Assert (Present (Prim));
+
+         if No (Prim) then
+            raise Program_Error;
+         end if;
       end loop;
 
       return Node (Prim);
@@ -1608,7 +1611,10 @@ package body Exp_Util is
       Prim := First_Elmt (Primitive_Operations (Typ));
       while not Is_TSS (Node (Prim), Name) loop
          Next_Elmt (Prim);
-         pragma Assert (Present (Prim));
+
+         if No (Prim) then
+            raise Program_Error;
+         end if;
       end loop;
 
       return Node (Prim);
index c5edce6d0856e3627ceec74fca81df135fce4a08..6a544c0072c3b8396ba31e8da2533c5cfeeadb34 100644 (file)
@@ -1578,25 +1578,44 @@ package body Sem_Ch8 is
                --  an abstract formal subprogram must be dispatching
                --  operation).
 
-               case Attribute_Name (Nam) is
-                  when Name_Input  =>
-                     Stream_Prim :=
-                       Find_Prim_Op (Prefix_Type, TSS_Stream_Input);
-                  when Name_Output =>
-                     Stream_Prim :=
-                       Find_Prim_Op (Prefix_Type, TSS_Stream_Output);
-                  when Name_Read   =>
-                     Stream_Prim :=
-                       Find_Prim_Op (Prefix_Type, TSS_Stream_Read);
-                  when Name_Write  =>
-                     Stream_Prim :=
-                       Find_Prim_Op (Prefix_Type, TSS_Stream_Write);
-                  when others      =>
-                     Error_Msg_N
-                       ("attribute must be a primitive dispatching operation",
-                        Nam);
-                     return;
-               end case;
+               begin
+                  case Attribute_Name (Nam) is
+                     when Name_Input  =>
+                        Stream_Prim :=
+                          Find_Prim_Op (Prefix_Type, TSS_Stream_Input);
+                     when Name_Output =>
+                        Stream_Prim :=
+                          Find_Prim_Op (Prefix_Type, TSS_Stream_Output);
+                     when Name_Read   =>
+                        Stream_Prim :=
+                          Find_Prim_Op (Prefix_Type, TSS_Stream_Read);
+                     when Name_Write  =>
+                        Stream_Prim :=
+                          Find_Prim_Op (Prefix_Type, TSS_Stream_Write);
+                     when others      =>
+                        Error_Msg_N
+                          ("attribute must be a primitive"
+                            & " dispatching operation", Nam);
+                        return;
+                  end case;
+               exception
+
+                  --  If no operation was found, and the type is limited,
+                  --  the user should have defined one.
+
+                  when Program_Error =>
+                     if Is_Limited_Type (Prefix_Type) then
+                        Error_Msg_NE
+                         ("stream operation not defined for type&",
+                           N, Prefix_Type);
+                        return;
+
+                     --  Otherwise, compiler should have generated default.
+
+                     else
+                        raise;
+                     end if;
+               end;
 
                --  Rewrite the attribute into the name of its corresponding
                --  primitive dispatching subprogram. We can then proceed with