This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/51151] New: Invalid -Woverflow warning in C++ frontend
- From: "ian at airs dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 16 Nov 2011 05:36:41 +0000
- Subject: [Bug c++/51151] New: Invalid -Woverflow warning in C++ frontend
- Auto-submitted: auto-generated
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.