This is the mail archive of the gcc-bugs@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]

[Bug ada/15588] New: Illegal program not detected, allows modifying a constant


-- RM 6.4.1(4)
-- If the mode is IN OUT or OUT, the actual shall be a name that
-- denotes a variable.
with text_io;
procedure main is
   type T1 is tagged record
     i: integer;
   end record;

   procedure p1(x: in out T1) is
   begin
      x.i := x.i + 1;
   end;

   procedure p2(y: T1'class) is
      subtype T2 is T1;
   begin
      p1(T2(y));      --ERROR: IN parameter passed to IN OUT
   end p2;

   c: constant T1 := (i => 2);

begin
   p2(c);
   text_io.put_line(integer'image(c.i));
end;

$ gnatmake main
gcc -c main.adb
gnatbind -x main.ali
gnatlink main.ali

Compilation finished at Wed Apr 14 18:51:51

The program's output is:

 3

which means the constant c has been overwritten.

-- 
Ludovic Brenta.

-- 
           Summary: Illegal program not detected, allows modifying a
                    constant
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: ludovic dot brenta at insalien dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


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