re PR c++/51433 (constexpr caching leads to incorrect dynamic initialization)
authorJason Merrill <jason@redhat.com>
Tue, 10 Jan 2012 14:37:26 +0000 (09:37 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Tue, 10 Jan 2012 14:37:26 +0000 (09:37 -0500)
PR c++/51433
* semantics.c (cxx_eval_call_expression): Always retry previously
non-constant expressions.

From-SVN: r183065

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C [new file with mode: 0644]

index c0e1cf4dd5f572abb5ae356c5f980be8edc89d1b..4de8ba158dbe34340b027a54cd8efd1ddbdf022d 100644 (file)
@@ -1,3 +1,9 @@
+2012-01-10  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51433
+       * semantics.c (cxx_eval_call_expression): Always retry previously
+       non-constant expressions.
+
 2012-01-06  Jason Merrill  <jason@redhat.com>
 
        DR 686
index fbb74e1e8de3716d3138c4f4f0385fc6b6ee16f9..2c351bee020151148f83851c3b504a5972e19f56 100644 (file)
@@ -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,
index f05d3e5182db3a9bc8d67ef553743cfe309d7ebb..0afad2796a1723a0f156070f076839f6daa87423 100644 (file)
@@ -1,3 +1,8 @@
+2012-01-10  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51433
+       * g++.dg/cpp0x/constexpr-cache1.C: New.
+
 2012-01-10  Richard Guenther  <rguenther@suse.de>
 
        PR tree-optimization/51801
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-cache1.C
new file mode 100644 (file)
index 0000000..b6d7b64
--- /dev/null
@@ -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");