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]

[Bug ada/33457] New: Renaming in context of ragged array

The object renaming does not behave properly as demonstrated with the test
codes below. Note that line 11 of message_services.adb contains the problem. In
addition, if line 11 is commented out and line 12 in uncommented, the codes
behave properly.

package Message_Services is
   type Message_Code is range 0 .. 100;

   subtype Message is String;

   function Get_Message (Code : Message_Code) return String;
   pragma Inline (Get_Message);

end Message_Services;

package body Message_Services is

   type Message_Handle is access constant Message;

   Message_0 : aliased constant Message := "OK";
   Message_1 : aliased constant Message := "Up";
   Message_2 : aliased constant Message := "Down";
   Message_3 : aliased constant Message := "Left";
   Message_4 : aliased constant Message := "Right";
   -- ...
   Default   : Message renames Message_0; -- bug here
--   Default   : aliased constant Message := Message_0; -- work around

   Message_Table : array (Message_Code) of Message_Handle := (
                     000 => Message_0'access,
                     001 => Message_1'access,
                     002 => Message_2'access,
                     003 => Message_3'access,
                     004 => Message_4'access,
                     others => Default'access);

   function Get_Message (Code : Message_Code) return String is
      return Message_Table (Code).all;
   end Get_Message;

end Message_Services;

with Ada.Text_IO;

procedure Message_Services.Test is

   use Ada;
   use Text_IO;

   Test_Message : constant Message := "OK";


   Put_Line ("Static Ragged Array construction, no heap involvement");

   for Index in Message_Code range 0 .. 9 loop
      Put_Line ("Message" & Message_Code'Image (Index) & " is: " & 
                   Get_Message (Index));   
   end loop;

   for Index in Message_Code range 5 .. 9 loop
      if Get_Message (Index) /= Test_Message then
         Put_Line ("Test fails");
      end if;   
   end loop;
   Put_Line ("Test passes");

end Message_Services.Test;

           Summary: Renaming in context of ragged array
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: anhvofrcaus at gmail dot com
 GCC build triplet: gcc-4.3-20070914
  GCC host triplet: Red Hat i686

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]