+2018-05-25 Ed Schonberg <schonberg@adacore.com>
+
+ * sem_ch6.adb (Analyze_Subprogram_Body_Helper): Do not create
+ Class_Wide_Clone_Body when analyzing a subprogram_body_stub: the clone
+ is created when the proper body of the stub is analyzed.
+ * sem_util.adb (ZBuild_Class_Wide_Clone_Body): If the subprogram body
+ is the proper body of a subunit, the cloned body must be inserted in
+ the declarative list that contains the stub.
+
2018-05-25 Justin Squirek <squirek@adacore.com>
* exp_ch6.adb (Expand_Simple_Function_Return): Add guard in check to
-- If the subprogram has a class-wide clone, build its body as a copy
-- of the original body, and rewrite body of original subprogram as a
-- wrapper that calls the clone.
+ -- If N is a stub, this construction will take place when the proper
+ -- body is analyzed.
if Present (Spec_Id)
and then Present (Class_Wide_Clone (Spec_Id))
and then (Comes_From_Source (N) or else Was_Expression_Function (N))
+ and then Nkind (N) /= N_Subprogram_Body_Stub
then
Build_Class_Wide_Clone_Body (Spec_Id, N);
-- (the original primitive may have carried one).
Set_Must_Override (Specification (Clone_Body), False);
- Insert_Before (Bod, Clone_Body);
+
+ -- If the subprogram body is the proper body of a stub, insert the
+ -- subprogram after the stub, i.e. the same declarative region as
+ -- the original sugprogram.
+
+ if Nkind (Parent (Bod)) = N_Subunit then
+ Insert_After (Corresponding_Stub (Parent (Bod)), Clone_Body);
+
+ else
+ Insert_Before (Bod, Clone_Body);
+ end if;
+
Analyze (Clone_Body);
end Build_Class_Wide_Clone_Body;