@@ -3282,6 +3282,13 @@ package body Exp_Attr is
Expr := Unchecked_Convert_To (Ptyp, First (Exprs));
+ -- Ensure that the expression is not truncated since the "bad" bits
+ -- are desired.
+
+ if Nkind (Expr) = N_Unchecked_Type_Conversion then
+ Set_No_Truncation (Expr);
+ end if;
+
Insert_Action (N,
Make_Raise_Constraint_Error (Loc,
Condition =>
new file mode 100644
@@ -0,0 +1,22 @@
+with Ada.Text_IO; use Ada.Text_IO;
+
+procedure Enum_Val1 is
+ type Enum is (Two, Four);
+ for Enum use (2, 4);
+
+ Count : Natural := 0;
+
+begin
+ for I in 10 .. 11 loop
+ begin
+ Put (Integer'Image (I) & ": ");
+ Put_Line (Enum'Image (Enum'Enum_Val (I)));
+ exception
+ when Constraint_Error =>
+ Count := Count + 1;
+ end;
+ end loop;
+ if Count /= 2 then
+ raise Program_Error;
+ end if;
+end;