C++ PATCH for c++/65398 (valid constexpr rejected)

Jason Merrill jason@redhat.com
Fri Mar 20 15:15:00 GMT 2015


On 03/20/2015 11:11 AM, Jakub Jelinek wrote:
>> &s[3] is the address of the terminal \0.
>
> Yeah, sure.  But the above testcase does &s[4], which is out of bounds
> arithmetics

But since &s[3] is the address of an element of the array (the NUL), 
&s[4] is one-past-the-end, which is fine.  &s[5] would be out of bounds.

> I'm not saying it is absolutely necessary to handle this for GCC 5, but
> we at least should not treat the POINTER_PLUS_EXPR offset in the constexpr
> handling as unsigned, but think of it as signed, otherwise we reject even
> valid code - say constexpr char d = *(&s[3] - 1).

Agreed.  And I still think it makes sense to fix this as part of this patch.

Jason



More information about the Gcc-patches mailing list