The code: #include <cstddef> static const char lwb = 0x80; static const char upb = 0x7f; static const size_t cnt = upb - lwb + 1;
static const char lwba = 0x80; static const char upba = 0x01; static const size_t cnta = upba - lwba + 1; static const char lwbb = 0xff; static const char upbb = 0x7f; static const size_t cntb = upbb - lwbb + 1; static const char lwbc = 0x00; static const char upbc = 0x7f; static const size_t cntc = upbc - lwbc + 1; int main() { return 0; } gets you: ~/ootbc/common/src$ c++ foo.cc foo.cc:5: warning: integer overflow in expression foo.cc:9: warning: integer overflow in expression foo.cc:13: warning: integer overflow in expression which (as I read the promotion rules) is incorrect. First lwb and upb should be promoted to int, then subtraction is done, and then the addition. This gives no overflow. However, it appears that the subtraction is actually being done in char, not int, because the results actually do overflow 127 on all but the last case. Have the promotion rules changed? Ivan -- Summary: incorrect overflow warning Product: gcc Version: 3.4.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: c++ AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: igodard at pacbell dot net CC: gcc-bugs at gcc dot gnu dot org http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20019