[Ada] Membership operations on fixed point universal arguments

Message ID 20100623091522.GA18716@adacore.com
State New
Headers show

Commit Message

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  <schonberg@adacore.com>

	* 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);