public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* C++ PATCH for c++/65876 (ICE with constexpr and arrays)
@ 2015-04-30 14:45 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2015-04-30 14:45 UTC (permalink / raw)
  To: gcc-patches List

[-- Attachment #1: Type: text/plain, Size: 371 bytes --]

In this testcase, we delay expanding the VEC_INIT_EXPR until 
gimplification time, at which point we've already thrown away some 
constexpr bodies.  Since this location doesn't require a constant 
expression we can safely treat it as a non-constant expression.

Tested x86_64-pc-linux-gnu, applying to 5 branch.  On the trunk I want 
to address the cause of the problem.

[-- Attachment #2: 65876-5.patch --]
[-- Type: text/x-patch, Size: 1644 bytes --]

commit 3dc40c07723fe4490a49176e7420ba5afe692db1
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Apr 28 22:17:30 2015 -0400

    	PR c++/65876
    	* constexpr.c (cxx_eval_call_expression): Fail gracefully if cgraph
    	threw away DECL_SAVED_TREE.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index 0e333aa..5e65f29 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -1355,7 +1355,14 @@ cxx_eval_call_expression (const constexpr_ctx *ctx, tree t,
 		     fun = DECL_CHAIN (fun))
 		  if (DECL_SAVED_TREE (fun))
 		    break;
-	      gcc_assert (DECL_SAVED_TREE (fun));
+	      if (!DECL_SAVED_TREE (fun))
+		{
+		  /* cgraph/gimplification have released the DECL_SAVED_TREE
+		     for this function.  Fail gracefully.  */
+		  gcc_assert (ctx->quiet);
+		  *non_constant_p = true;
+		  return t;
+		}
 	      tree parms, res;
 
 	      /* Unshare the whole function body.  */
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array12.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array12.C
new file mode 100644
index 0000000..ec81fff
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array12.C
@@ -0,0 +1,33 @@
+// PR c++/65876
+// { dg-do compile { target c++11 } }
+
+template<int>
+struct duration
+{
+    constexpr duration() : r(0) {}
+
+    template<int TPeriod>
+    constexpr duration(duration<TPeriod> x) : r(x.count()) {}
+
+    constexpr int count() { return 0; }
+
+    int r;
+};
+
+struct Config {
+    duration<1> timeout { duration<2>() };
+};
+
+Config make_config()
+{
+    return {};
+}
+
+struct ConfigArray {
+    ConfigArray();
+    Config all_configs[1];
+};
+
+ConfigArray::ConfigArray()
+{
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2015-04-30 14:21 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-30 14:45 C++ PATCH for c++/65876 (ICE with constexpr and arrays) Jason Merrill

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).