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] Program_Unit pragmas in generic units are inherited by instances


Pragmas on generic units, if they are not library unit pragmas, are inherited
by each instantiation of the generic. Pragma Convention was omitted from this
processing.

The following must execute quietly:

   gnatmake -q address_test.adb
   address_test

---
with Ada.Text_Io; use Ada.Text_IO;
with Interfaces;
with System.Address_Image;
use System;

procedure Address_Test is

   Addr_1 : System.Address;
   Addr_2 : System.Address;

   generic
      type Item_Type is limited private;
   function Test_Address (Item : in Item_Type) return Interfaces.Unsigned_64;
   pragma Convention (C, Test_Address);

   function Test_Address (Item : in Item_Type) return Interfaces.Unsigned_64 is
   begin
      Addr_2 := Item'Address;
      return 1;
   end;

   type Object_Type is
      record
         Data_01 : Interfaces.Unsigned_64 := 01;
         Data_02 : Interfaces.Unsigned_64 := 02;
      end record;

   type Object_Type_2 is
      record
         Data_01 : Interfaces.Unsigned_64 := 01;
         Data_02 : Interfaces.Unsigned_64 := 02;
         Data_03 : Interfaces.Unsigned_64 := 03;
      end record;

   function Test_Object_Address is new Test_Address (Item_Type => Object_Type);

   Test_Object : Object_Type;

   function Test_Object_2_Address is
      new Test_Address (Item_Type => Object_Type_2);

   Test_Object_2 : Object_Type_2;

   U64 : Interfaces.Unsigned_64 := 666;

begin
   Addr_1 := Test_Object'Address;
   U64 := Test_Object_Address (Item => Test_Object);
   if Addr_1 /= Addr_2 then
      Put_Line ("Test_Object: different addresses");
   end if;

   Addr_1 := Test_Object_2'Address;
   U64 := Test_Object_2_Address (Item => Test_Object_2);
   if Addr_1 /= Addr_2 then
      Put_Line ("Test_Object_2: different addresses");
   end if;
end Address_Test;

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

2011-09-02  Ed Schonberg  <schonberg@adacore.com>

	* sem_ch12.adb (Analyze_Subprogram_Instantiation): If the
	generic unit is not intrinsic and has an explicit convention,
	the instance inherits it.

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]