public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/20573] New: unable to use cast to suppress "warning: comparison is always false due to limited range of data type"
@ 2005-03-21 0:17 gcc-bugzilla at gcc dot gnu dot org
2005-03-21 0:24 ` [Bug c/20573] " pinskia at gcc dot gnu dot org
2005-03-21 3:49 ` sthoenna at efn dot org
0 siblings, 2 replies; 3+ messages in thread
From: gcc-bugzilla at gcc dot gnu dot org @ 2005-03-21 0:17 UTC (permalink / raw)
To: gcc-bugs
There doesn't seem to be an easy way to suppress this warning in a macro like
#define MILL(in) ((in) > 1000000)
where the macro may be passed different sizes of ints including shorts.
I would have expected the warning to be suppressed when a cast is present
like:
#define MILL(in) ((int)(in) > 1000000)
but it isn't.
Environment:
System: CYGWIN_NT-5.1 DHX98431 1.5.14s(0.124/4/2) 20050319 16:46:09 i686 unknown unknown Cygwin
host: i686-pc-cygwin
build: i686-pc-cygwin
target: i686-pc-cygwin
configured with: /gcc/3.4/gcc-3.4.1-1/configure --verbose --prefix=/usr --exec-prefix=/usr --sysconfdir=/etc --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --enable-languages=c,ada,c++,f77,java,objc --enable-nls --without-included-gettext --enable-libgcj --with-system-zlib --enable-interpreter --enable-threads=posix --enable-java-gc=boehm --enable-sjlj-exceptions --disable-version-specific-runtime-libs --disable-win32-registry
How-To-Repeat:
Given warnme.c:
#define MILL(in) ((in) > 1000000)
int foo(short s) { return MILL(s); }
int bar(short s) { return MILL((int)s); }
int baz(short s) { int i=s; return MILL(i); }
with preprocessor output warnme.i:
# 1 "warnme.c"
# 1 "<built-in>"
# 1 "<command line>"
# 1 "warnme.c"
int foo(short s) { return ((s) > 1000000); }
int bar(short s) { return (((int)s) > 1000000); }
int baz(short s) { int i=s; return ((i) > 1000000); }
$ gcc -Wall -save-temps -c warnme.c
warnme.c: In function `foo':
warnme.c:2: warning: comparison is always false due to limited range of data type
warnme.c: In function `bar':
warnme.c:3: warning: comparison is always false due to limited range of data type
The warning in foo is expected; the warning in bar is not. baz is an ugly
workaround.
------- Additional Comments From sthoenna at efn dot org 2005-03-21 00:16 -------
Fix:
An ugly workaround is to assign to a temporary variable of large enough data
type where the macro is called, and pass the temporary variable instead.
--
Summary: unable to use cast to suppress "warning: comparison is
always false due to limited range of data type"
Product: gcc
Version: 3.4.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: sthoenna at efn dot org
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i686-pc-cygwin
GCC host triplet: i686-pc-cygwin
GCC target triplet: i686-pc-cygwin
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20573
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/20573] unable to use cast to suppress "warning: comparison is always false due to limited range of data type"
2005-03-21 0:17 [Bug c/20573] New: unable to use cast to suppress "warning: comparison is always false due to limited range of data type" gcc-bugzilla at gcc dot gnu dot org
@ 2005-03-21 0:24 ` pinskia at gcc dot gnu dot org
2005-03-21 3:49 ` sthoenna at efn dot org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-03-21 0:24 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-21 00:24 -------
A better way is to just to suppress the warning point, see PR 12963.
*** This bug has been marked as a duplicate of 12963 ***
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |DUPLICATE
Summary|unable to use cast to |unable to use cast to
|suppress "warning: |suppress "warning:
|comparison is always false |comparison is always false
|due to limited range of data|due to limited range of data
|type" |type"
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20573
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/20573] unable to use cast to suppress "warning: comparison is always false due to limited range of data type"
2005-03-21 0:17 [Bug c/20573] New: unable to use cast to suppress "warning: comparison is always false due to limited range of data type" gcc-bugzilla at gcc dot gnu dot org
2005-03-21 0:24 ` [Bug c/20573] " pinskia at gcc dot gnu dot org
@ 2005-03-21 3:49 ` sthoenna at efn dot org
1 sibling, 0 replies; 3+ messages in thread
From: sthoenna at efn dot org @ 2005-03-21 3:49 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From sthoenna at efn dot org 2005-03-21 03:49 -------
Subject: Re: unable to use cast to suppress "warning: comparison is always false due to limited range of data type"
On Mon, Mar 21, 2005 at 12:24:32AM -0000, pinskia at gcc dot gnu dot org wrote:
>
> ------- Additional Comments From pinskia at gcc dot gnu dot org 2005-03-21 00:24 -------
> A better way is to just to suppress the warning point, see PR 12963.
But I don't want to suppress the warning in general; it's a valuable
warning. I just want to be able to have a macro that takes an
arbitrarily sized int and compares it.
> *** This bug has been marked as a duplicate of 12963 ***
Thanks. I mistakenly searched Comments containing '"comparison is
always"' instead of 'comparison is always' :) or I would have found
that one.
It's interesting to note that the apparent ending point of the discussion
there is my starting point: that a cast should suppress the warning (but
I would hope not the optimization).
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20573
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-03-21 3:49 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-21 0:17 [Bug c/20573] New: unable to use cast to suppress "warning: comparison is always false due to limited range of data type" gcc-bugzilla at gcc dot gnu dot org
2005-03-21 0:24 ` [Bug c/20573] " pinskia at gcc dot gnu dot org
2005-03-21 3:49 ` sthoenna at efn dot org
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).