[Bug ada/34496] New: [4.2 regression] prefixed notation allows changing the value of a constant

ludovic at ludovic-brenta dot org gcc-bugzilla@gcc.gnu.org
Sun Dec 16 13:57:00 GMT 2007


with text_io;
procedure test1 is
   package pak3 is

      type T1 is tagged record
         x0: integer;
      end record;

      procedure p1 (x1: access T1; val: integer);

      x2: aliased constant T1 := (x0 => 3);
      x3: access constant T1 := x2'access;

   end pak3;

   package body pak3 is
      procedure p1 (x1: access T1; val: integer) is
      begin
         x1.x0 := val;
      end p1;
   end pak3;

begin
   text_io.put_line(integer'image(pak3.x2.x0));
   pak3.x2.p1(5); -- line 25
   text_io.put_line(integer'image(pak3.x2.x0));
   pak3.x3.all.p1(7); -- line 27
-- pak3.x3.p1(7);       -- this one is detected
   text_io.put_line(integer'image(pak3.x2.x0));
end test1;

GCC 4.1.2:

$ gnatmake -gnat05 test1
gcc-4.1 -c -gnat05 test1.adb
test1.adb:25:08: expected an access type with designated type "T1" defined at
line 5
test1.adb:25:08: found type "T1" defined at line 5
test1.adb:27:12: expected an access type with designated type "T1" defined at
line 5
test1.adb:27:12: found type "T1" defined at line 5

The error messages are not very good (they should say something like "found
type "constant T1"") but the program is indeed illegal.

GCC 4.2.2:

$ gnatmake -gnat05 test1
gcc-4.2 -c -gnat05 test1.adb
gnatbind -x test1.ali
gnatlink test1.ali
$ ./test1
 3
 5
 7


-- 
           Summary: [4.2 regression] prefixed notation allows changing the
                    value of a constant
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ludovic at ludovic-brenta dot org


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



More information about the Gcc-bugs mailing list