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] Constraint_Error on spurious ambiguity in instance


This patch updates the instantiation machinery to properly preserve a reference
to a global type in a qualified expression used to convert a universal literal
to a specific type, and propagate it to the instantiated template.

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

--  types.ads

package Types is
   type Uint is private;
   type Int is range -2**31 .. +2**31 - 1;

   function "+" (Left : Uint; Right : Uint) return Uint;
   function "+" (Left : Int;  Right : Uint) return Uint;
   function "+" (Left : Uint; Right : Int)  return Uint;

   function "*" (Left : Uint; Right : Uint) return Uint;
   function "*" (Left : Int;  Right : Uint) return Uint;
   function "*" (Left : Uint; Right : Int)  return Uint;

private
   Uint_Low_Bound  : constant := 600_000_000;
   Uint_High_Bound : constant := 2_099_999_999;

   type Uint is new Int range Uint_Low_Bound .. Uint_High_Bound;
   No_Uint : constant Uint := Uint (Uint_Low_Bound);
end Types;

--  types.adb

package body Types is
   function "+" (Left : Uint; Right : Uint) return Uint is
   begin return No_Uint; end "+";
   function "+" (Left : Int;  Right : Uint) return Uint is
   begin return No_Uint; end "+";
   function "+" (Left : Uint; Right : Int)  return Uint is
   begin return No_Uint; end "+";

   function "*" (Left : Uint; Right : Uint) return Uint is
   begin return No_Uint; end "+";
   function "*" (Left : Int;  Right : Uint) return Uint is
   begin return No_Uint; end "+";
   function "*" (Left : Uint; Right : Int)  return Uint is
   begin return No_Uint; end "+";
end Types;

--  types_gen.ads

generic
package Types_Gen is
   procedure Compute;
end Types_Gen;

--  types_gen.adb

with Types; use Types;

package body Types_Gen is
   procedure Compute is
      UI_Int_Value : Uint;
   begin
      UI_Int_Value := UI_Int_Value * 10 + 20;
   end Compute;
end Types_Gen;

--  types_inst.ads

with Types_Gen;

package Types_Inst is new Types_Gen;

-----------------
-- Compilation --
-----------------

$ gcc -c -gnatct types_inst.ads

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

2016-04-20  Hristian Kirtchev  <kirtchev@adacore.com>

	* sem_ch12.adb (Copy_Generic_Node): Handle the special
	qualification installed for universal literals that act as
	operands in binary or unary operators.	(Qualify_Operand): Mark
	the qualification to signal the instantiation mechanism how to
	handle global reference propagation.
	* sinfo.adb (Is_Qualified_Universal_Literal): New routine.
	(Set_Is_Qualified_Universal_Literal): New routine.
	* sinfo.ads New attribute Is_Qualified_Universal_Literal along
	with occurrences in nodes.
	(Is_Qualified_Universal_Literal):
	New routine along with pragma Inline.
	(Set_Is_Qualified_Universal_Literal): New routine along with
	pragma Inline.

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]