testcase, compile with -pedantic-errors (we don't reject it overwise in 4.3):
unsigned char p;
unsigned char p1 = p & 512;
------------- cut -------
We get:
overflow-warn-5.c:7: warning: overflow in implicit constant conversion
overflow-warn-5.c:7: error: overflow in constant expression

Now there is an overflow but only because we optimize the IR (unsigned
char)(((int)p)& 512) into:
p & (unsigned char)512 and (unsigned char)512 is converted into 0 (with
overflow) so we have p & 0 which is then optimized into 0(with overflow).  So
we are only rejecting this because of the overflow due to the conversion (which
was due to fold).


We don't reject as invalid code either:
unsigned char p;
unsigned char p1 = p & 0;


-- 
           Summary: Wrong error message with unsigned char a = uchar&512
           Product: gcc
           Version: 4.3.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, diagnostic
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pinskia at gcc dot gnu dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32643

Reply via email to