public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51151] New: Invalid -Woverflow warning in C++ frontend
@ 2011-11-16  6:15 ian at airs dot com
  2011-11-17  1:44 ` [Bug c++/51151] " ian at airs dot com
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: ian at airs dot com @ 2011-11-16  6:15 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51151
           Summary: Invalid -Woverflow warning in C++ frontend
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ian@airs.com


Compile this C++ file with -Wall or -Woverflow:

template<typename T> class C {
public:
  void f() {
    m = c2 + 1;
  }
  static const long unsigned int c1 = 7;
  static const int c2 = c1 - 1;
  int m;
};
template class C<int>;

When I compile this with current mainline, I get:

foo.cc: In instantiation of ‘void C<T>::f() [with T = int]’:
foo.cc:10:16:   required from here
foo.cc:4:5: warning: integer overflow in expression [-Woverflow]

This warning is invalid.  There is no integer overflow here.

From a quick look, it appears that fold winds up being called with
    ((int) ((unsigned int) 7 + 4294967295U)) + 1
It decides to distribute the addition, groups the constants 4294967295 and 1
together, and gets an overflow when it adds them.  At that point it is adding
together an unsigned and a signed constant, having decided to strip the type
conversion as a nop.

This does not happen when not using a template.


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

end of thread, other threads:[~2012-01-03  8:37 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-11-16  6:15 [Bug c++/51151] New: Invalid -Woverflow warning in C++ frontend ian at airs dot com
2011-11-17  1:44 ` [Bug c++/51151] " ian at airs dot com
2011-12-09 20:52 ` jason at gcc dot gnu.org
2011-12-14 12:03 ` krebbel at gcc dot gnu.org
2011-12-14 12:11 ` krebbel at gcc dot gnu.org
2011-12-14 14:33 ` dominiq at lps dot ens.fr
2012-01-02 17:35 ` paolo.carlini at oracle dot com
2012-01-02 17:35 ` aaw at gcc dot gnu.org
2012-01-03  8:36 ` krebbel at gcc dot gnu.org
2012-01-03  8:37 ` krebbel at gcc dot gnu.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).