Patchwork [Ada] Membership operations on fixed point universal arguments

mail settings
Submitter Arnaud Charlet
Date June 23, 2010, 9:15 a.m.
Message ID <>
Download mbox | patch
Permalink /patch/56619/
State New
Headers show


Arnaud Charlet - June 23, 2010, 9:15 a.m.
With this patch the compiler handles properly the case of a membership op.
where the left operand is of any fixed point type because it is a mixed-mode
operation with universal operands, and the right operand is a range with
universal bounds.

The following must compile and produce the warning:

   warning: universal_fixed expression interpreted as type "Standard.Duration"

procedure Bug is
  Nr1: Integer := 15;  --  Works when variables are float
  if (Nr1 - 1) * 20.0E-6 in 0.75E-3 .. 1.15E-3 then
  end if;
end Bug;

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

2010-06-23  Ed Schonberg  <>

	* sem_res.adb (Resolve_Membership_Op): If left operand is a mixed mode
	operation with a universal real operand, and the right operand is a
	range with universal bounds, find unique fixed point that may be
	candidate, and warn appropriately.


Index: sem_res.adb
--- sem_res.adb	(revision 161263)
+++ sem_res.adb	(working copy)
@@ -7036,6 +7036,18 @@  package body Sem_Res is
          T := Intersect_Types (L, R);
       end if;
+      --  If mixed-mode operations are present and operands are all literal,
+      --  the only interpretation involves Duration, which is probably not
+      --  the intention of the programmer.
+      if T = Any_Fixed then
+         T := Unique_Fixed_Point_Type (N);
+         if T = Any_Type then
+            return;
+         end if;
+      end if;
       Resolve (L, T);
       Check_Unset_Reference (L);