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] Bug in handling of library-level freeze actions


This patch fixes an error in the handling of freeze actions generated for
a generic package that is a compilation unit, whose entities carry iterable
aspects.

The following must compile quietly:

---
generic
   type Data_Type (<>) is limited private;
package Data_Streams is

   type Root_Data_Stream_Type is abstract tagged limited null record;

   function Has_Data (Stream : Root_Data_Stream_Type)
     return Boolean is abstract;

   function Consume (Stream : not null access Root_Data_Stream_Type)
     return Data_Type is abstract;


   generic
      type Data_Stream_Type is new Root_Data_Stream_Type with private;
   package Add_Iteration is

      type Iterable_Data_Stream_Type is new Data_Stream_Type with private
        with Iterable => (First => First, Next => Next,
          Has_Element => Has_Element, Element => Element);

      type Cursor is private;

      function First (Stream : Iterable_Data_Stream_Type) return Cursor;

      function Next (
        Stream   : Iterable_Data_Stream_Type;
        Position : Cursor
      ) return Cursor;

      function Has_Element (
        Stream   : Iterable_Data_Stream_Type;
        Position : Cursor
      ) return Boolean;

      function Element (
        Stream   : Iterable_Data_Stream_Type;
        Position : Cursor
      ) return Data_Type;

   private

      type Reference_Type (Stream : not null access Iterable_Data_Stream_Type)
        is null record;

      type Iterable_Data_Stream_Type is new Data_Stream_Type with record
         Self : Reference_Type (Iterable_Data_Stream_Type'Access);
      end record;

     type Cursor is null record;

   end Add_Iteration;

end Data_Streams;
---
package body Data_Streams is

   package body Add_Iteration is

      function First (Stream : Iterable_Data_Stream_Type) return Cursor is
      begin
         return (null record);
      end First;
   
      function Has_Element (
        Stream   : Iterable_Data_Stream_Type;
        Position : Cursor
      ) return Boolean is
      begin
         return Has_Data (Stream);
      end Has_Element;
   
      function Next (
        Stream   : Iterable_Data_Stream_Type;
        Position : Cursor
      ) return Cursor is
      begin
         return (null record);
      end Next;
   
      function Element (
        Stream   : Iterable_Data_Stream_Type;
        Position : Cursor
      ) return Data_Type is
      begin
         return Consume (Stream.Self.Stream);
      end Element;

   end Add_Iteration;

end Data_Streams;

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

2017-05-02  Ed Schonberg  <schonberg@adacore.com>

	* exp_util.adb (Insert_Library_Level_Action): Use proper scope
	to analyze generated actions.  If the main unit is a body,
	the required scope is that of the corresponding unit declaration.

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]