end if;
end if;
+ -- Generate a tag check for view conversions of mutably tagged objects,
+ -- which are special in nature and require selecting the tag component
+ -- from the class-wide equivalent type.
+
+ -- Possibly this could be combined with the logic below for better code
+ -- reuse ???
+
+ if Is_View_Conversion (N)
+ and then Is_Variable (Operand)
+ and then Is_Class_Wide_Equivalent_Type (Etype (Operand))
+ then
+ -- Generate:
+ -- [Constraint_Error when Operand.Tag /= Root_Type]
+
+ Insert_Action (N,
+ Make_Raise_Constraint_Error (Loc,
+ Condition =>
+ Make_Op_Ne (Loc,
+ Left_Opnd =>
+ Make_Selected_Component (Loc,
+ Prefix => Duplicate_Subexpr_No_Checks (Operand),
+ Selector_Name => Make_Identifier (Loc, Name_uTag)),
+ Right_Opnd =>
+ Make_Attribute_Reference (Loc,
+ Prefix => New_Occurrence_Of (Target_Type, Loc),
+ Attribute_Name => Name_Tag)),
+ Reason => CE_Tag_Check_Failed));
+
-- Case of conversions of tagged types and access to tagged types
-- When needed, that is to say when the expression is class-wide, Add
-- and then Operand.all not in
-- Designated_Type (Target_Type)'Class]
- if (Is_Access_Type (Target_Type)
- and then Is_Tagged_Type (Designated_Type (Target_Type)))
+ elsif (Is_Access_Type (Target_Type)
+ and then Is_Tagged_Type (Designated_Type (Target_Type)))
or else Is_Tagged_Type (Target_Type)
then
-- Do not do any expansion in the access type case if the parent is a