On 03/19/2015 02:05 PM, Jakub Jelinek wrote:
Though, a question is if we do (or, if we don't and should) reject say
constexpr char s[] = "abc";
constexpr int j = 4;
constexpr char c = *(&s[j] - 2);
because there was out of bound access in there.

I don't see an out-of-bound access in this example; taking the address of one-past-the-end is OK as long as you don't try to access through it.

Unfortunately we reject even that (regardless the patch), and yeah, it's
because of how POINTER_PLUS_EXPR uses sizetype as a type of the second operand.

This seems like something to fix in this patch.

+             tree t = fold_convert_loc (loc, TREE_TYPE (op01),
+                                        TREE_OPERAND (op00, 1));
+             t = size_binop_loc (loc, PLUS_EXPR, op01, t);

This seems to be assuming that the elements are size 1.

Jason

Reply via email to