This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Ada] Extensions of constrained discriminated with other progenitors


If the parent type in a type extension is a discriminated type with constraints,
the compiler creates an anonymous base type for it, and makes the source type
into a subtype of it. If the derived type declaration includes an interface
list, it is attached to the anonymous base type. However, the extension may
contain current instances of the source type, whose subtype declaration has not
been elaborated yet. The interface list must be linked to the source type as
soon as constructed for the base. The presence of the anonymous base type must
also be taken into account when building the interface thunks for overridden 
interface operations: the overriding operation is declared on the subtype, but
the inherited primitive has the signature of the anonymous base.

The following must compile and execute quietly:

---
with Ref; use Ref;
procedure Proc is
   Obj :Grand_Child;
begin
   Dispatch (I'Class (Obj));
end;
---
package Ref is
   type I is interface;
   procedure Check (Obj : I) is null;
   procedure Dispatch (Obj : I'class);
   type C is record
      V : access I'Class;
   end record;

   type Root (V : Integer) is tagged null record;

   type Child is new Root (1) with null record;

   type Grand_Child is new Child and I with record
      X : C := (V => Grand_Child'Unrestricted_Access);
   end record;
   procedure Check (Obj : Grand_Child);
end Ref;
---
package body Ref is
   procedure Dispatch (Obj : I'class) is
   begin
      Check (Obj);
   end;

   procedure Check (Obj : Grand_Child) is
   begin
      if Obj.X.V /= Obj'Unrestricted_Access then raise Program_Error; end if;
   end;
end Ref;
---

Tested on x86_64-pc-linux-gnu, committed on trunk

2010-06-14  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch3.adb (Build_Derived_Record_Type): if derived type is an
	anonymous base generated when the parent is a constrained discriminated
	type, propagate interface list to first subtype because it may appear
	in a current instance within the extension part of the derived type
	declaration, and its own subtype declaration has not been elaborated
	yet.
	* exp_disp.adb (Build_Interface_Thunk): Use base type of formal to
	determine whether it has the controlling type.

Attachment: difs
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]