This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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.

Attachment: fixpr36607.diff.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]