===================================================================
@@ -6512,7 +6512,9 @@
begin
-- The prefix of attribute 'Valid should always denote an object
-- reference. The reference is either coming directly from source
- -- or is produced by validity check expansion.
+ -- or is produced by validity check expansion. The object may be
+ -- wrapped in a conversion in which case the call to Unqual_Conv
+ -- will yield it.
-- If the prefix denotes a variable which captures the value of
-- an object for validation purposes, use the variable in the
@@ -6523,7 +6525,7 @@
-- if not Temp in ... then
if Is_Validation_Variable_Reference (Pref) then
- Temp := New_Occurrence_Of (Entity (Pref), Loc);
+ Temp := New_Occurrence_Of (Entity (Unqual_Conv (Pref)), Loc);
-- Otherwise the prefix is either a source object or a constant
-- produced by validity check expansion. Generate:
===================================================================
@@ -0,0 +1,11 @@
+-- { dg-do compile }
+-- { dg-options "-gnatVi -gnatws" }
+
+with Validity_Check2_Pkg; use Validity_Check2_Pkg;
+
+procedure Validity_Check2 (R : access Rec) is
+begin
+ if Op_Code_To_Msg (R.Code) in Valid_Msg then
+ raise Program_Error;
+ end if;
+end;
===================================================================
@@ -0,0 +1,16 @@
+with Ada.unchecked_conversion;
+
+package Validity_Check2_Pkg is
+
+ type Op_Code is (One, Two, Three, Four);
+
+ subtype Valid_Msg is Integer range 0 .. 15;
+
+ function Op_Code_To_Msg is
+ new Ada.Unchecked_Conversion (Source => Op_code, Target => Valid_Msg);
+
+ type Rec is record
+ Code : Op_Code;
+ end record;
+
+end Validity_Check2_Pkg;