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] Class-wide type invariants for type extensions in other units.


A class-wide type invariant is inherited by a type extension, and incorporated
into the invariant procedure for that type. When the expression for such an
invariant (typically a function call) is first analyzed, we must preserve some
semantic information in it, because the type extension may be declared in a
different unit, where it cannot be resolved by visibility if it refers to
local entities.

The following must compile quietly:
   gcc -c -gnata inv2.ads

---
package Inv1 is
   type T_Inv1 is tagged private with
      Type_Invariant'Class => Invariant (T_Inv1);

   function Invariant (This : in T_Inv1'Class) return Boolean;
   type T_Inv2 is new Inv1.T_Inv1 with private;

private
   type T_Inv1 is tagged record
      Value : Integer := 1234;
   end record;

   function Invariant (This : in T_Inv1'Class) return Boolean is
      (This.Value > 1000);

   type T_Inv2 is new Inv1.T_Inv1 with null record;
end Inv1;
---
with Inv1;
package Inv2 is
   type T_Inv2 is new Inv1.T_Inv1 with private;
private
   type T_Inv2 is new Inv1.T_Inv1 with null record;
end Inv2;

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

2014-10-17  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch13.adb (Add_Invariants): For a class-wide type invariant,
	preserve semantic information on the invariant expression
	(typically a function call) because it may be inherited by a
	type extension in a different unit, and it cannot be resolved
	by visibility elsewhere because it may refer to local entities.

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]