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

Reply via email to