This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: C++ PATCH for c++/65398 (valid constexpr rejected)
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: Richard Biener <richard dot guenther at gmail dot com>, Marek Polacek <polacek at redhat dot com>, GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Fri, 20 Mar 2015 16:11:20 +0100
- Subject: Re: C++ PATCH for c++/65398 (valid constexpr rejected)
- Authentication-results: sourceware.org; auth=none
- References: <20150313144052 dot GU26802 at redhat dot com> <CAFiYyc02=2DsHrEAADcNLATjGm0BK9Dp1kUb17ZnFDMcGCWpqQ at mail dot gmail dot com> <20150319180536 dot GA1746 at tucnak dot redhat dot com> <550C347E dot 2070801 at redhat dot com> <20150320145937 dot GH1746 at tucnak dot redhat dot com> <550C36A3 dot 2080605 at redhat dot com>
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
On Fri, Mar 20, 2015 at 11:02:59AM -0400, Jason Merrill wrote:
> On 03/20/2015 10:59 AM, Jakub Jelinek wrote:
> >On Fri, Mar 20, 2015 at 10:53:50AM -0400, Jason Merrill wrote:
> >>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.
> >
> >It is taking address of two past the end though - &s[3] is fine, sure.
> >But &s[4] is invalid already.
>
> &s[3] is the address of the terminal \0.
Yeah, sure. But the above testcase does &s[4], which is out of bounds
arithmetics, and then subtracts 2 to point it back into range.
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).
Jakub