Re: C++ PATCH for c++/65398 (valid constexpr rejected once again)

2015-03-30 Thread Jason Merrill
OK, thanks. Jason

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

2015-03-30 Thread Marek Polacek
Turned out that my earlier fix for this PR didn't handle cases where we aren't dealing with an INDIRECT_REF expression, which means we fail to compile valid code. Fixed by moving the folding to cxx_eval_constant_expression, where we ought to be able to reduce all POINTER_PLUS_EXPRs in a constexpr

Re: C++ PATCH for c++/65398 (valid constexpr rejected) (take 2)

2015-03-20 Thread Jason Merrill
On 03/20/2015 05:03 PM, Jakub Jelinek wrote: Hi! Just for completeness: On Fri, Mar 20, 2015 at 09:56:52PM +0100, Marek Polacek wrote: +constexpr char d1 = *(&s[4] - 0); // { dg-error "array subscript out of bound" } +constexpr char d2 = *(&s[4] - 1); +constexpr char d3 = *(&s[4] - 2); +const

Re: C++ PATCH for c++/65398 (valid constexpr rejected) (take 2)

2015-03-20 Thread Jakub Jelinek
Hi! Just for completeness: On Fri, Mar 20, 2015 at 09:56:52PM +0100, Marek Polacek wrote: > +constexpr char d1 = *(&s[4] - 0); // { dg-error "array subscript out of > bound" } > +constexpr char d2 = *(&s[4] - 1); > +constexpr char d3 = *(&s[4] - 2); > +constexpr char d4 = *(&s[4] - 3); > +conste

Re: C++ PATCH for c++/65398 (valid constexpr rejected) (take 2)

2015-03-20 Thread Marek Polacek
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

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

2015-03-20 Thread Jakub Jelinek
On Fri, Mar 20, 2015 at 11:15:30AM -0400, Jason Merrill wrote: > 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 o

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

2015-03-20 Thread Jason Merrill
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

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

2015-03-20 Thread Jakub Jelinek
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 sa

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

2015-03-20 Thread Jason Merrill
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 = *(&

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

2015-03-20 Thread Jakub Jelinek
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

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

2015-03-20 Thread Jason Merrill
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 exampl

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

2015-03-19 Thread Marek Polacek
On Thu, Mar 19, 2015 at 07:17:23PM +0100, Jakub Jelinek wrote: > On Thu, Mar 19, 2015 at 07:13:47PM +0100, Marek Polacek wrote: > > On Thu, Mar 19, 2015 at 07:05:36PM +0100, Jakub Jelinek wrote: > > > I believe cxx_fold_indirect_ref result is not passed through to the > > > middle-end, unless it ca

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

2015-03-19 Thread Jakub Jelinek
On Thu, Mar 19, 2015 at 07:13:47PM +0100, Marek Polacek wrote: > On Thu, Mar 19, 2015 at 07:05:36PM +0100, Jakub Jelinek wrote: > > I believe cxx_fold_indirect_ref result is not passed through to the > > middle-end, unless it can be folded into a constant. > > > > Though, a question is if we do (o

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

2015-03-19 Thread Marek Polacek
On Thu, Mar 19, 2015 at 07:05:36PM +0100, Jakub Jelinek wrote: > On Wed, Mar 18, 2015 at 11:08:15AM +0100, Richard Biener wrote: > > On Fri, Mar 13, 2015 at 3:40 PM, Marek Polacek wrote: > > > We started to reject this (IMHO valid) testcase with r214941 that did > > > away with > > > try_move_mul

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

2015-03-19 Thread Jakub Jelinek
On Wed, Mar 18, 2015 at 11:08:15AM +0100, Richard Biener wrote: > On Fri, Mar 13, 2015 at 3:40 PM, Marek Polacek wrote: > > We started to reject this (IMHO valid) testcase with r214941 that did away > > with > > try_move_mult_to_index -- meaning that we are no longer able to fold > > *(&s[0] + 1

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

2015-03-18 Thread Richard Biener
On Fri, Mar 13, 2015 at 3:40 PM, Marek Polacek wrote: > We started to reject this (IMHO valid) testcase with r214941 that did away > with > try_move_mult_to_index -- meaning that we are no longer able to fold *(&s[0] > + 1) > into s[1], while we are able to fold *(s + 1) into s[1]. > > I suppose

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

2015-03-13 Thread Marek Polacek
We started to reject this (IMHO valid) testcase with r214941 that did away with try_move_mult_to_index -- meaning that we are no longer able to fold *(&s[0] + 1) into s[1], while we are able to fold *(s + 1) into s[1]. I suppose cxx_fold_indirect_ref ought to be able to handle both cases, so I a