This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/51151] New: Invalid -Woverflow warning in C++ frontend


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]