public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "ian at airs dot com" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/51151] New: Invalid -Woverflow warning in C++ frontend Date: Wed, 16 Nov 2011 06:15:00 -0000 [thread overview] Message-ID: <bug-51151-4@http.gcc.gnu.org/bugzilla/> (raw) 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.
next reply other threads:[~2011-11-16 5:37 UTC|newest] Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-11-16 6:15 ian at airs dot com [this message] 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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-51151-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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).