This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/24542] New: integer overflow should be warned on assignment to wider variable
- From: "alexey at hyperroll dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 26 Oct 2005 14:54:16 -0000
- Subject: [Bug c/24542] New: integer overflow should be warned on assignment to wider variable
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The following code is ISO and ANSI standard compliant:
unsigned x1, x2;
unsigned long long y1;
... /* here we assign to x1 and x2 */
y1 = x1 * x2; /* no castings -- silent overflow may occur on assignment */
...
{
unsigned long long y2 = x1 * x2; /* no castings -- silent overflow may
occur on initialization */
...
}
(Instead of multiplication, addition or left shift shold be dealt with, too.)
When the binary operation result is assigned to lvalue of the same width, it's
OK not to warn about probable overflow. But in these cases, "do what I mean" is
obvious.
--
Summary: integer overflow should be warned on assignment to wider
variable
Product: gcc
Version: 4.0.2
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: alexey at hyperroll dot com
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=24542