Message ID | 4F0C4C55.5050006@redhat.com |
---|---|
State | New |
Headers | show |
On Tue, Jan 10, 2012 at 8:33 AM, Jason Merrill <jason@redhat.com> wrote: > Sometimes an expression that is non-constant at one point in the translation > unit can become constant later, when a constexpr function is defined. So > let's not cache failure. > > Tested x86_64-pc-linux-gnu, applying to trunk. This isn't a regression, but > as before, since C++11 support is still experimental I consider patches that > fix C++11 bugs and don't affect C++98 code to be acceptable. Thanks! with hindsight, it is "obvious" :-) -- Gaby
commit 639cadeb21c26f4d5e98e9bf2b211a4c39a61b9c Author: Jason Merrill <jason@redhat.com> Date: Mon Jan 9 09:40:34 2012 -0500 PR c++/51433 * semantics.c (cxx_eval_call_expression): Always retry previously non-constant expressions. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index fbb74e1..2c351be 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6576,7 +6576,7 @@ cxx_eval_call_expression (const constexpr_call *old_call, tree t, else { result = entry->result; - if (!result || (result == error_mark_node && !allow_non_constant)) + if (!result || result == error_mark_node) result = (cxx_eval_constant_expression (&new_call, new_call.fundef->body, allow_non_constant, addr, diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C new file mode 100644 index 0000000..b6d7b64 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C @@ -0,0 +1,9 @@ +// PR c++/51433 +// { dg-options -std=c++0x } + +constexpr int f(); +constexpr int g() { return f(); } +extern const int n = g(); // dynamic initialization +constexpr int f() { return 42; } +extern const int m = g(); +static_assert(m == 42, "m == 42");