From patchwork Wed Jun 23 09:15:22 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Ada] Membership operations on fixed point universal arguments Date: Tue, 22 Jun 2010 23:15:22 -0000 From: Arnaud Charlet X-Patchwork-Id: 56619 Message-Id: <20100623091522.GA18716@adacore.com> To: gcc-patches@gcc.gnu.org Cc: Ed Schonberg 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 * 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);