public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "dnovillo at gcc dot gnu dot org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/33738]  New: -Wtype-limits misses a warning when comparing enums
Date: Thu, 11 Oct 2007 17:50:00 -0000	[thread overview]
Message-ID: <bug-33738-91@http.gcc.gnu.org/bugzilla/> (raw)

This was found on GCC 4.2.1.  In this test case, VRP quietly folds a comparison
between an enum type and a constant value that the enum type can never take.
With -Wtype-limits, this should give the warning:

comparison always false due to limited range of data type

extern void link_error (void);

enum Alpha {
 ZERO = 0, ONE, TWO, THREE
};

Alpha a2;

int m1 = -1;
int GetM1() {
 return m1;
}

int main() {
 a2 = static_cast<Alpha>(GetM1());
 if (a2 == -1) {                   <-- VRP should warn when folding this.
    link_error ();
 }
 return 0;
}

This is not warned by the front end because we promote -1 to the same type as
a2.  But during VRP, we *do* fold the predicate, so warning when -Wtype-limits
is given in this case would be a good QOI feature.

I have a patch in the works to make VRP warn when it linearizes this predicate.


-- 
           Summary: -Wtype-limits misses a warning when comparing enums
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: dnovillo at gcc dot gnu dot org
        ReportedBy: dnovillo at gcc dot gnu dot org


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


             reply	other threads:[~2007-10-11 17:50 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-11 17:50 dnovillo at gcc dot gnu dot org [this message]
2007-10-11 18:09 ` [Bug c++/33738] " pinskia at gcc dot gnu dot org
2007-11-13  4:56 ` manu at gcc dot gnu dot org
2008-02-05  4:19 ` dnovillo at gcc dot gnu dot org
2008-02-05  4:30 ` dnovillo at gcc dot gnu dot org
2008-02-05 10:19 ` rguenth at gcc dot gnu dot org
2008-02-05 11:22 ` manu at gcc dot gnu dot org
2008-02-05 16:16 ` dnovillo at google dot com
2008-02-05 16:32 ` dnovillo at gcc dot gnu dot org
2008-02-05 19:54 ` reichelt at gcc dot gnu dot org
2008-02-05 19:57 ` manu at gcc dot gnu dot org
2008-02-05 19:59 ` pinskia at gcc dot gnu dot org
2008-02-24 16:42 ` dnovillo at gcc dot gnu dot org
2008-03-11  5:56 ` dnovillo at gcc dot gnu dot org
2008-12-29  6:11 ` pinskia at gcc dot gnu 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=bug-33738-91@http.gcc.gnu.org/bugzilla/ \
    --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).