------- Comment #3 from manu at gcc dot gnu dot org  2007-07-08 10:12 -------
(In reply to comment #0)
> testcase, compile with -pedantic-errors (we don't reject it overwise in 4.3):
> unsigned char p;
> unsigned char p1 = p & 512;
> 
> 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).

There should not be any overflow? So the result is wrong independently whether
this is an initialization or not? The operation should be done with int, isn't
it?  

BTW, you should get two warnings when using -pedantic.

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

Why should we? There is no overflow here, you mean that p is not constant? I
think we have two issues in the first testcase, one is folding (X op 0), the
other is converting 512 to uchar before performing the operation. Am I wrong?


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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

Reply via email to