This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/43772] Errant -Wlogical-op warning when testing limits


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

eggert at gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |eggert at gnu dot org

--- Comment #7 from eggert at gnu dot org 2011-06-15 19:18:57 UTC ---
I get the same bug with GCC 4.6.0 (x86-64).  Here's a test case:

long long
emacs_lseek (int fd, long long offset, int whence)
{
  return -1-9223372036854775807LL <= offset && offset <= 9223372036854775807LL;
}

This is abstracted from real EMACS source code: the real code is verifying
that an EMACS_INT value fits within off_t.  Both types happen to be
'long long' here, but they might not be the same types on other platforms.

When compiled with "gcc -S -Wlogical-op t.c", I get:

t.c: In function 'emacs_lseek':
t.c:5:3: warning: logical 'and' of mutually exclusive tests is always false
[-Wlogical-op]

which is obviously bogus.

Using "&" rather than "&&" works around the bug, but that's not a
satisfactory solution in general.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]