A recent change to reduce duplication of compiler-generated Put_Image and
streaming subprograms introduced two regressions. One is yet another of the
many cases where generating these routines "on demand" (as opposed at the
point of the associated type declaration) requires loosening the compiler's
enforcement of privacy. The other is a use-before-definition issue that
occurs because the declaration of a Put_Image procedure is not hoisted far
enough.
gcc/ada/
* exp_attr.adb (Build_And_Insert_Type_Attr_Subp): If a subprogram
associated with a (library-level) type declared in another unit is
to be inserted somewhere in a list, then insert it at the head of
the list.
* sem_ch5.adb (Analyze_Assignment): Normally a limited-type
assignment is illegal. Relax this rule if Comes_From_Source is
False and the type is not immutably limited.
while Present (Ancestor) loop
if Is_List_Member (Ancestor) then
- Insertion_Point := Ancestor;
+ Insertion_Point := First (List_Containing (Ancestor));
+ pragma Assert (Present (Insertion_Point));
end if;
Ancestor := Parent (Ancestor);
end loop;
-- Error of assigning to limited type. We do however allow this in
-- certain cases where the front end generates the assignments.
+ -- Comes_From_Source test is needed to allow compiler-generated
+ -- streaming/put_image subprograms, which may ignore privacy.
elsif Is_Limited_Type (T1)
and then not Assignment_OK (Lhs)
and then not Assignment_OK (Original_Node (Lhs))
+ and then (Comes_From_Source (N) or Is_Immutably_Limited_Type (T1))
then
-- CPP constructors can only be called in declarations