This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/43772] Errant -Wlogical-op warning when testing limits
- From: "eggert at gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 15 Jun 2011 19:19:46 +0000
- Subject: [Bug c/43772] Errant -Wlogical-op warning when testing limits
- Auto-submitted: auto-generated
- References: <bug-43772-4@http.gcc.gnu.org/bugzilla/>
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.