| Submitter | Jason Merrill |
|---|---|
| Date | Jan. 21, 2011, 6:59 p.m. |
| Message ID | <4D39D7A9.4030109@redhat.com> |
| Download | mbox | patch |
| Permalink | /patch/79882/ |
| State | New |
| Headers | show |
Comments
On Fri, Jan 21, 2011 at 12:59 PM, Jason Merrill <jason@redhat.com> wrote: > Having to deal with general constant-expressions as null pointer constants > has been a hassle, as it means that we have to try to evaluate something for > a constant value in a lot more situations. Here we were trying to evaluate > S::x before wrapping it in NON_DEPENDENT_EXPR. Fixed simply by handing > OFFSET_REF in cxx_eval_constant_expression. As you probably know, I believe C++0x should ban the arbitrary constant expression evaluating to zero as a null constant expression. 0 or nullptr should be enough for everybody :-) -- Gaby
Patch
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index 23ff27b..fa35d4a 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -7024,6 +7024,7 @@ cxx_eval_constant_expression (const constexpr_call *call, tree t, case NON_DEPENDENT_EXPR: case BASELINK: case EXPR_STMT: + case OFFSET_REF: if (!allow_non_constant) error_at (EXPR_LOC_OR_HERE (t), "expression %qE is not a constant-expression", t); diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-regress2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-regress2.C new file mode 100644 index 0000000..470ee1c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-regress2.C @@ -0,0 +1,13 @@ +// PR c++/46552 +// { dg-options -std=c++0x } + +struct S +{ + int x; +}; + +template < typename > +void f( void ) +{ + &S::x; +}
Having to deal with general constant-expressions as null pointer constants has been a hassle, as it means that we have to try to evaluate something for a constant value in a lot more situations. Here we were trying to evaluate S::x before wrapping it in NON_DEPENDENT_EXPR. Fixed simply by handing OFFSET_REF in cxx_eval_constant_expression. Tested x86_64-pc-linux-gnu, applied to trunk. commit e0dc36cb0542b1dd1ca55d3d80769812dbccdbd2 Author: Jason Merrill <jason@redhat.com> Date: Fri Jan 21 12:37:01 2011 -0500 PR c++/46552 * semantics.c (cxx_eval_constant_expression): Handle OFFSET_REF.