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/15005] New: Illegal program not detected 8.5.1(5); allows subverting type system


GCC 3.4, 3.5 compile the following illegal program without complaining.

With GNAT 3.15p I get:

gnatgcc -c main.adb
main.adb:23:29: illegal renaming of discriminant-dependent component
gnatmake: "main.adb" compilation error


-- RM 8.5.1(5)
-- The renamed entity shall not be a subcomponent that depends
-- on a variable whose nominal subtype is unconstrained.
with text_io; use text_io;
procedure main is
   function char_to_int(ch: character) return integer is

      type union (b: boolean := false) is record
	 case b is
	    when false  => i: integer;
	    when true   => c: character;
	 end case;
      end record;

      type wrapper is record
	 u: union;
      end record;

      type wrapper_ptr is access wrapper;

      x: wrapper_ptr := new wrapper;

      j: integer renames x.u.i;       --ERROR: x.u is unconstrained

   begin
      x.u := (b => true, c => ch);
      return j;
   end char_to_int;

begin
   put_line(integer'image(char_to_int('A')));
end;

-- 
           Summary: Illegal program not detected 8.5.1(5); allows subverting
                    type system
           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: i386-pc-linux
  GCC host triplet: i386-pc-linux
GCC target triplet: i386-pc-linux


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


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