2008-08-04 Robert Dewar <dewar@adacore.com>
authorRobert Dewar <dewar@adacore.com>
Mon, 4 Aug 2008 12:51:00 +0000 (14:51 +0200)
committerArnaud Charlet <charlet@gcc.gnu.org>
Mon, 4 Aug 2008 12:51:00 +0000 (14:51 +0200)
* sem_res.adb:
(Valid_Conversion): Catch case of designated types having different
sizes, even though they statically match.

From-SVN: r138615

gcc/ada/sem_res.adb

index d59c30bc0f9dbedf476e88aae96f5d8176efc5e6..4e0e0dedfcd97f6cd38c236e4049237838304569 100644 (file)
@@ -9519,7 +9519,27 @@ package body Sem_Res is
                       (not Is_Constrained (Opnd)
                         or else not Is_Constrained (Target)))
                then
-                  return True;
+                  --  Special case, if Value_Size has been used to make the
+                  --  sizes different, the conversion is not allowed even
+                  --  though the subtypes statically match.
+
+                  if Known_Static_RM_Size (Target)
+                    and then Known_Static_RM_Size (Opnd)
+                    and then RM_Size (Target) /= RM_Size (Opnd)
+                  then
+                     Error_Msg_NE
+                       ("target designated subtype not compatible with }",
+                        N, Opnd);
+                     Error_Msg_NE
+                       ("\because sizes of the two designated subtypes differ",
+                        N, Opnd);
+                     return False;
+
+                  --  Normal case where conversion is allowed
+
+                  else
+                     return True;
+                  end if;
 
                else
                   Error_Msg_NE