[PATCH] Fix PR C++/36607 Incorrect type diagnostic on substracting casted char pointers

Andrew Pinski pinskia@gmail.com
Wed Dec 31 03:20:00 GMT 2008


Hi,
  The problem here is that fold will fold NOP_EXPR<INT, a +
OFFSET_TYPE_var> - NOP_EXPR<INT, a> into NOP_EXPR <INT,
OFFSET_TYPE_var> and then when converting (via convert) that
expression into a smaller type like short, there would be an error.
This error is incorrect as the user actually did not have a conversion
from an offset type directly to an integer type, they went through
pointer subtraction.

Since the front-end already errors out when converting offset type
expressions to integer types, convert can just treat OFFSET_TYPE like
INTEGER_TYPE and the other types.

OK?  Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Thanks,
Andrew Pinski

ChangeLog:
* convert.c (convert_to_integer): Treat OFFSET_TYPE like INTEGER_TYPE.

* g++.dg/expr/cast10.C: New test.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: fixpr36607.diff.txt
URL: <http://gcc.gnu.org/pipermail/gcc-patches/attachments/20081231/1a469e68/attachment.txt>


More information about the Gcc-patches mailing list