public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [Ada] Membership operations on fixed point universal arguments
@ 2010-06-23  9:53 Arnaud Charlet
  0 siblings, 0 replies; only message in thread
From: Arnaud Charlet @ 2010-06-23  9:53 UTC (permalink / raw)
  To: gcc-patches; +Cc: Ed Schonberg

[-- Attachment #1: Type: text/plain, Size: 911 bytes --]

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:

bug.adb:4:26:
   warning: universal_fixed expression interpreted as type "Standard.Duration"

procedure Bug is
  Nr1: Integer := 15;  --  Works when variables are float
begin
  if (Nr1 - 1) * 20.0E-6 in 0.75E-3 .. 1.15E-3 then
	null;
  else
	null;
  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.


[-- Attachment #2: difs --]
[-- Type: text/plain, Size: 676 bytes --]

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-06-23  9:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-06-23  9:53 [Ada] Membership operations on fixed point universal arguments Arnaud Charlet

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).