The library PNG_IO fails during elaboration while performing some sanity checks
on its internal functions.

This was created on i386-redhat-linux-gnu (Centos 4)

I have boiled this down to a pretty simple test case that looks like the issue
happens when a function is returning a constrained subtype of an unconstrained
array and it is doing so when building the return value from an expression.

The following code should print   abcd. Instead, it prints several garbage
characters.

with Text_IO;
with Interfaces; use Interfaces;
procedure Slice_Bug is

  subtype Slice_Type is String(1 .. 4);

  function identity(A : in Character) return Character is
  begin
    return a;
  end identity;


  function Get_Slice return Slice_Type is
  begin
   return identity('a') & identity('b')  & identity('c') & identity('d');
  end Get_Slice;

begin
  Text_IO.Put_Line(Get_Slice);
end Slice_Bug;


Removing the constraint from the subtype makes this code work as expected.
Leaving the constraint in and doing a simple return "abcd" also works.


-- 
           Summary: Incorrect result returning constrained subtype (slice)
                    with non-trivial return expression
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: jeff at thecreems dot com


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

Reply via email to