public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/33738]  New: -Wtype-limits misses a warning when comparing enums
@ 2007-10-11 17:50 dnovillo at gcc dot gnu dot org
  2007-10-11 18:09 ` [Bug c++/33738] " pinskia at gcc dot gnu dot org
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: dnovillo at gcc dot gnu dot org @ 2007-10-11 17:50 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2008-12-29  6:11 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-11 17:50 [Bug c++/33738] New: -Wtype-limits misses a warning when comparing enums dnovillo at gcc dot gnu dot org
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

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).