recompile the program, you can run it with different values being used
for initializing otherwise uninitialized values, to test if your program
behavior depends on the choice. Of course the behavior should not change,
-and if it does, then most likely you have an erroneous reference to an
+and if it does, then most likely you have an incorrect reference to an
uninitialized value.
It is even possible to change the value at execution time eliminating even
integer field, and so the default size of record objects for this type
will be 64 (8 bytes).
+A consequence of this capability is that different object sizes can be
+given to subtypes that would otherwise be considered in Ada to be
+statically matching. But it makes no sense to consider such subtypes
+as statically matching. Consequently, in @code{GNAT} we add a rule
+to the static matching rules that requires object sizes to match.
+Consider this example:
+
+@smallexample @c ada
+ 1. procedure BadAVConvert is
+ 2. type R is new Integer;
+ 3. subtype R1 is R range 1 .. 10;
+ 4. subtype R2 is R range 1 .. 10;
+ 5. for R1'Object_Size use 8;
+ 6. for R2'Object_Size use 16;
+ 7. type R1P is access all R1;
+ 8. type R2P is access all R2;
+ 9. R1PV : R1P := new R1'(4);
+10. R2PV : R2P;
+11. begin
+12. R2PV := R2P (R1PV);
+ |
+ >>> target designated subtype not compatible with
+ type "R1" defined at line 3
+
+13. end;
+@end smallexample
+
+@noindent
+In the absence of lines 5 and 6,
+types @code{R1} and @code{R2} statically match and
+hence the conversion on line 12 is legal. But since lines 5 and 6
+cause the object sizes to differ, @code{GNAT} considers that types
+@code{R1} and @code{R2} are not statically matching, and line 12
+generates the diagnostic shown above.
+
+@noindent
+Similar additional checks are performed in other contexts requiring
+statically matching subtypes.
+
@node Attribute Passed_By_Reference
@unnumberedsec Attribute Passed_By_Reference
@cindex Parameters, when passed by reference
can cause the RM 13.1(14) rule to be violated. If two access types
reference aliased objects whose subtypes have differing @code{Object_Size}
values as a result of explicit attribute definition clauses, then it
-is erroneous to convert from one access subtype to the other.
+is illegal to convert from one access subtype to the other. For a more
+complete description of this additional legality rule, see the
+description of the @code{Object_Size} attribute.
At the implementation level, Esize stores the Object_Size and the
RM_Size field stores the @code{Value_Size} (and hence the value of the
-- they are the same identical constraint, or if they are static and the
-- values match (RM 4.9.1(1)).
+ -- In addition, in GNAT, the object size (Esize) values of the types must
+ -- match if they are set. The use of 'Object_Size can cause this to be
+ -- false even if the types would otherwise match in the RM sense.
+
function Subtypes_Statically_Match (T1, T2 : Entity_Id) return Boolean is
function Predicates_Match return Boolean;
if Ada_Version < Ada_2012 then
return True;
+ -- Both types must have predicates or lack them
+
elsif Has_Predicates (T1) /= Has_Predicates (T2) then
return False;
+ -- Check matching predicates
+
else
Pred1 :=
Get_Rep_Item
if T1 = T2 then
return True;
+ -- No match if sizes different (from use of 'Object_Size)
+
+ elsif Known_Static_Esize (T1) and then Known_Static_Esize (T2)
+ and then Esize (T1) /= Esize (T2)
+ then
+ return False;
+
-- Scalar types
elsif Is_Scalar_Type (T1) then
function Subtypes_Statically_Match (T1, T2 : Entity_Id) return Boolean;
-- Determine whether two types T1, T2, which have the same base type,
- -- are statically matching subtypes (RM 4.9.1(1-2)).
+ -- are statically matching subtypes (RM 4.9.1(1-2)). Also includes the
+ -- extra GNAT rule that object sizes must match (this can be false for
+ -- types that match in the RM sense because of use of 'Object_Size).
function Compile_Time_Known_Value (Op : Node_Id) return Boolean;
-- Returns true if Op is an expression not raising Constraint_Error whose