This is the mail archive of the 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] Pragma Import on library units that are generic subprograms

Tested on i686-linux, committed on trunk

A generic subprogram may be imported, in which case it does not have a body.
The consistency check on generic units in the context of the current compilation
must omit imported generics, because their body will be provided elsewhere.

Importing generic subprograms provides a limited form of instance sharing.

The following must compile and execute quietly:

gcc -c convert.c
gnatmake import_generic -largs convert.o

   type Source (<>) is limited private;
   type Target (<>) is limited private;
function gf1 (S : Source) return Target;
pragma Import (C, gf1, "convert");

int convert (int x) { return x * x * x;}

with Gf1;
with Text_IO; use Text_IO;
procedure Import_Generic is
   function Cube is new gf1 (Integer, Integer);

   type Int is new Integer;
   function Cube2 is new fg1 (Int. Int);

   if Cube (3) /= 27 then
      raise Program_Error;
   end if;

   if Cube2 (3) /= 27 then
      raise Program_Error;
   end if;

2008-03-26  Ed Schonberg  <>

	* sem_ch10.adb (Analyze_Compilation_Unit): if a unit in the context is
	a generic subprogram that is imported, do not attempt to compile
	non-existent body.

	* sem_ch12.adb (Instantiate_Subprogram_Body): if the generic is
	imported, do not generate a raise_program_error for the non-existent
	(Pre_Analyze_Actuals): If an error is detected during pre-analysis,
	perform minimal name resolution on the generic to avoid spurious
	(Find_Actual_Type): the designated type of the actual in a child unit
	may be declared in a parent unit without being an actual.

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]