With trunk GCC, SVN revision 138798.

The following program (t.adb), when compiled with "gcc -O2", gives:

t.adb: In function ‘T’:
t.adb:6: warning: comparison always false due to limited range of data type

(probably emitted by the backend as "-gnatv" doesn't show the caret position)

Note that the warning points onto the line containing 'Pos, not the comparison
itself. And this is bogus, as if "X" contains "2#11xxxxxx#" (two high bits
set), then right shifting it by 6 positions (it is unsigned) will give "3",
which corresponds to "White".

Moreover, despites the warning, the generated code is correct and returns "0"
when the two high bits are set and "1" otherwise.

with Interfaces; use Interfaces;

function T (X : Unsigned_8) return Integer
is
   type Color is (None, Red, Blue, White);
   V : constant Color := Color'Val (Shift_Right (X, 6));
begin
   if V = White then
      return 0;
   else
      return 1;
   end if;
end T;


-- 
           Summary: Bogus warning from GCC
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: ada
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: sam at gcc dot gnu dot org
  GCC host triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37038

Reply via email to