public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "gcc-bugzilla at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/20573] New: unable to use cast to suppress "warning: comparison is always false due to limited range of data type"
Date: Mon, 21 Mar 2005 00:17:00 -0000	[thread overview]
Message-ID: <20050321001637.20573.sthoenna@efn.org> (raw)


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


             reply	other threads:[~2005-03-21  0:17 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-21  0:17 gcc-bugzilla at gcc dot gnu dot org [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20050321001637.20573.sthoenna@efn.org \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).