]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
PR c++/70344
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 Mar 2016 18:23:04 +0000 (18:23 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Wed, 23 Mar 2016 18:23:04 +0000 (18:23 +0000)
* constexpr.c (cxx_eval_call_expression): Catch invalid recursion.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@234434 138bc75d-0d04-0410-961f-82ee72b054a4

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

index d36168957ca6e62419b676fc05882a560c0fd38b..01fc2bd7657499e404b0814a43c1f39107ead240 100644 (file)
@@ -1,3 +1,8 @@
+2016-03-23  Jason Merrill  <jason@redhat.com>
+
+       PR c++/70344
+       * constexpr.c (cxx_eval_call_expression): Catch invalid recursion.
+
 2016-03-23  Marek Polacek  <polacek@redhat.com>
 
        PR c++/69884
index 7b136330b3f2ed923f668f3c95b09db6f50f5258..d71e488d5e09c23d646c0721771ab35e4dc1cc5e 100644 (file)
@@ -1239,6 +1239,21 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
       return t;
     }
 
+  if (fun == current_function_decl)
+    {
+      /* A call to the current function, i.e.
+        constexpr int f (int i) {
+          constexpr int j = f(i-1);
+          return j;
+        }
+        This would be OK without the constexpr on the declaration of j.  */
+      if (!ctx->quiet)
+       error_at (loc, "%qD called in a constant expression before its "
+                 "definition is complete", fun);
+      *non_constant_p = true;
+      return t;
+    }
+
   constexpr_ctx new_ctx = *ctx;
   if (DECL_CONSTRUCTOR_P (fun) && !ctx->object
       && TREE_CODE (t) == AGGR_INIT_EXPR)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-recursion2.C
new file mode 100644 (file)
index 0000000..978b998
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/70344
+// { dg-do compile { target c++11 } }
+
+struct Z
+{
+  Z () = default;
+  Z (Z const &) = default;
+  constexpr Z (Z &&) {}
+};
+
+constexpr int
+fn (Z v)
+{
+  return fn (v);
+}
+
+auto t = fn (Z ());