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

[Ada] Type conversion to String causes Constraint_Error


This patch modifies the mechanism which creates a subtype from an arbitrary
expression. The mechanism now captures the bounds of all index constraints
when the expression is of an array type.

------------
-- Source --
------------

--  pack.ads

with Ada.Finalization; use Ada.Finalization;

package Pack is
   type Ctrl is new Controlled with record
      Flag : Boolean := False;
   end record;

   type New_String is new String;

   function Make_Ctrl return Ctrl;
   function Make_String (Val : String) return New_String;
end Pack;

--  pack.adb

package body Pack is
   function Make_Ctrl return Ctrl is
      Result : Ctrl;
   begin
      return Result;
   end Make_Ctrl;

   function Make_String (Val : String) return New_String is
   begin
      return New_String (Val);
   end Make_String;
end Pack;

--  pack2.ads

package Pack2 is
   procedure Reproduce;
end Pack2;

--  pack2.adb

with Ada.Text_IO; use Ada.Text_IO;
with Pack;        use Pack;

package body Pack2 is
   Str : constant New_String := Make_String ("Hello");
   Ctr : constant Ctrl := Make_Ctrl;

   procedure Reproduce is
   begin
      Put_Line (String (Str));
   end Reproduce;
end Pack2;

--  main.adb

with Pack2; use Pack2;

procedure Main is
begin
   Reproduce;
end Main;

----------------------------
-- Compilation and output --
----------------------------

$ gnatmake -q main.adb
$ ./main
Hello

Tested on x86_64-pc-linux-gnu, committed on trunk

2014-11-20  Hristian Kirtchev  <kirtchev@adacore.com>

	* exp_util.adb (Make_Subtype_From_Expr): Capture the bounds of
	all index constracts when the expression is of an array type.

Attachment: difs
Description: Text document


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