Message ID | 20170103133708.GF8104@redhat.com |
---|---|
State | New |
Headers | show |
OK. On Tue, Jan 3, 2017 at 8:37 AM, Marek Polacek <polacek@redhat.com> wrote: > The problem here is that we've gotten to potential_constant_expression_1 with a > CLEANUP_STMT, but it doesn't know how to handle that so we ICE. I thought it'd > be possible to look into CLEANUP_{BODY,EXPR} to determine whether the > CLEANUP_STMT can be potentially const, but cxx_eval_constant_expression can't > handle CLEANUP_STMTs so it couldn't evaluate it anyway. So it seems that it's > safe to consider CLEANUP_STMTs non-constant. > > This happens when initializing __for_range, where finish_eh_cleanup creates > a CLEANUP_STMT that would run ~A() in case of an exception. > > Bootstrapped/regtested on x86_64-linux, ok for trunk? > > 2017-01-03 Marek Polacek <polacek@redhat.com> > > PR c++/77545 > PR c++/77284 > * constexpr.c (potential_constant_expression_1): Handle CLEANUP_STMT. > > * g++.dg/cpp0x/range-for32.C: New test. > * g++.dg/cpp0x/range-for33.C: New test. > > diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c > index 1e83b0b..a3dec68 100644 > --- gcc/cp/constexpr.c > +++ gcc/cp/constexpr.c > @@ -5661,6 +5661,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, > /* We can see these in statement-expressions. */ > return true; > > + case CLEANUP_STMT: > case EMPTY_CLASS_EXPR: > return false; > > diff --git gcc/testsuite/g++.dg/cpp0x/range-for32.C gcc/testsuite/g++.dg/cpp0x/range-for32.C > index e69de29..375a707 100644 > --- gcc/testsuite/g++.dg/cpp0x/range-for32.C > +++ gcc/testsuite/g++.dg/cpp0x/range-for32.C > @@ -0,0 +1,16 @@ > +// PR c++/77545 > +// { dg-do compile { target c++11 } } > +// { dg-options "-Wno-pedantic" } > + > +template < typename T > struct A > +{ > + A (); > + ~A (); > + T t; > +}; > + > +void f (A < int > a) > +{ > + for (auto x : (A<int>[]) { a }) > + ; > +} > diff --git gcc/testsuite/g++.dg/cpp0x/range-for33.C gcc/testsuite/g++.dg/cpp0x/range-for33.C > index e69de29..206f36e 100644 > --- gcc/testsuite/g++.dg/cpp0x/range-for33.C > +++ gcc/testsuite/g++.dg/cpp0x/range-for33.C > @@ -0,0 +1,14 @@ > +// PR c++/77284 > +// { dg-do compile { target c++11 } } > + > +#include <initializer_list> > + > +struct A > +{ > + ~A () {} > +}; > + > +void foo (A & v) > +{ > + for (A a : { v }) {}; > +} > > Marek
diff --git gcc/cp/constexpr.c gcc/cp/constexpr.c index 1e83b0b..a3dec68 100644 --- gcc/cp/constexpr.c +++ gcc/cp/constexpr.c @@ -5661,6 +5661,7 @@ potential_constant_expression_1 (tree t, bool want_rval, bool strict, /* We can see these in statement-expressions. */ return true; + case CLEANUP_STMT: case EMPTY_CLASS_EXPR: return false; diff --git gcc/testsuite/g++.dg/cpp0x/range-for32.C gcc/testsuite/g++.dg/cpp0x/range-for32.C index e69de29..375a707 100644 --- gcc/testsuite/g++.dg/cpp0x/range-for32.C +++ gcc/testsuite/g++.dg/cpp0x/range-for32.C @@ -0,0 +1,16 @@ +// PR c++/77545 +// { dg-do compile { target c++11 } } +// { dg-options "-Wno-pedantic" } + +template < typename T > struct A +{ + A (); + ~A (); + T t; +}; + +void f (A < int > a) +{ + for (auto x : (A<int>[]) { a }) + ; +} diff --git gcc/testsuite/g++.dg/cpp0x/range-for33.C gcc/testsuite/g++.dg/cpp0x/range-for33.C index e69de29..206f36e 100644 --- gcc/testsuite/g++.dg/cpp0x/range-for33.C +++ gcc/testsuite/g++.dg/cpp0x/range-for33.C @@ -0,0 +1,14 @@ +// PR c++/77284 +// { dg-do compile { target c++11 } } + +#include <initializer_list> + +struct A +{ + ~A () {} +}; + +void foo (A & v) +{ + for (A a : { v }) {}; +}