http://gcc.gnu.org/bugzilla/show_bug.cgi?id=48293

           Summary: Legal program rejected, empty discriminant blocks
                    object allocation with built-in-place
           Product: gcc
           Version: 4.6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: demoon...@panathenaia.halfmoon.jp


Created attachment 23774
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23774
minimal bug triggering source code

Compiler rejects allocating limited-type with function call (built-in-place) if
the limited type has *empty* discriminant.
(simple workaround is available, adding *dummy* discriminant)

with Ada.Finalization;
procedure min is
   -- bug sample
   package P1 is
      type T (<>) is limited private;
      function F return T;
   private
      type T is new Ada.Finalization.Limited_Controlled with null record;
   end P1;
   package body P1 is
      function F return T is
      begin
         return (Ada.Finalization.Limited_Controlled with null record);
      end F;
   end P1;
   X1 : P1.T := P1.T'(P1.F); -- OK
-- X2 : access P1.T := new P1.T; -- this code is illegal, it should be error.
   X3 : access P1.T := new P1.T'(P1.F); -- this code is legal, but error
   --  workaround
   package P2 is
      type T (<>) is limited private;
      function F return T;
   private
      type T (Dummy : Integer) is new Ada.Finalization.Limited_Controlled with
null record;
      --  add dummy discriminants
   end P2;
   package body P2 is
      function F return T is
      begin
         return (Ada.Finalization.Limited_Controlled with Dummy => 0);
      end F;
   end P2;
   X4 : access P2.T := new P2.T'(P2.F); -- OK
begin
   null;
end min;

Reply via email to