Message ID | 4D39C06E.9040401@redhat.com |
---|---|
State | New |
Headers | show |
On Fri, Jan 21, 2011 at 9:20 AM, Jason Merrill <jason@redhat.com> wrote: > The crash here came because we were trying to fold_non_dependent_expr the > statement-expression, which meant testing it for value-dependence, which > crashed because value_dependent_expression_p doesn't know how to handle > STMT_EXPR. > > The second patch, which I'm checking in, improves > potential_constant_expression to be a predicate that we can use on template > expressions in C++0x mode to determine whether or not the expression could > possibly be a constant expression. In C++98 mode it always returns true, as > we filtered out unsuitable expressions earlier in the parser. > > Tested x86_64-pc-linux-gnu, applied to trunk. > > diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog > index 2491047..21dce62 100644 > --- a/gcc/cp/ChangeLog > +++ b/gcc/cp/ChangeLog > @@ -1,5 +1,17 @@ > 2011-01-17 Jason Merrill <jason@redhat.com> > > + PR c++/46977 > + * semantics.c (potential_constant_expression_1): Split out from > + potential_constant_expression. Add want_rval parm. Handle > + template expression forms. Don't enforce restriction on address > + of automatic variable here. Add a couple of diagnostics that > + had been missing. > + (require_potential_constant_expression): New entry point. > + (build_data_member_initialization, register_constexpr_fundef): > Adjust. > + (maybe_constant_value): Check potential_constant_expression. > + * pt.c (fold_non_dependent_expr_sfinae): Likewise. > + * tree.c (build_vec_init_expr): Adjust. > + This patch caused: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47511
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 16bd2a0..32b2520 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -18142,6 +18142,11 @@ value_dependent_expression_p (tree expression) return false; } + case STMT_EXPR: + /* Return true for a statement-expression. FIXME this isn't + value-dependent, it's non-constant. */ + return true; + default: /* A constant expression is value-dependent if any subexpression is value-dependent. */ diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-stmtexpr.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-stmtexpr.C new file mode 100644 index 0000000..40e0c2d --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-stmtexpr.C @@ -0,0 +1,8 @@ +// PR c++/46977 +// { dg-options "-std=c++0x" } + +template < typename > void +foo () +{ + ({int i;}), 0; +}