This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++ PATCH for c++/64701 (ICE with statement-expression)


On 01/23/2015 09:43 AM, Jason Merrill wrote:
The constexpr expansion code doesn't understand the C++ front end
statement tree codes; for expanding a constexpr call it expects the
gimplified form.  For now let's not bother trying to expand a
statement-expression.

This is what I'm actually checking in:

commit 32714acccf980898b3973e34a1034fa07ebe8dee
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Jan 21 16:44:24 2015 -0500

    	PR c++/64701
    	* constexpr.c (maybe_constant_value): Just hand back STATEMENT_LIST.

diff --git a/gcc/cp/constexpr.c b/gcc/cp/constexpr.c
index f144ab0..f143420 100644
--- a/gcc/cp/constexpr.c
+++ b/gcc/cp/constexpr.c
@@ -3454,8 +3454,18 @@ cxx_eval_constant_expression (const constexpr_ctx *ctx, tree t,
       break;
 
     default:
-      internal_error ("unexpected expression %qE of kind %s", t,
-		      get_tree_code_name (TREE_CODE (t)));
+      if (STATEMENT_CODE_P (TREE_CODE (t)))
+	{
+	  /* This function doesn't know how to deal with pre-genericize
+	     statements; this can only happen with statement-expressions,
+	     so for now just fail.  */
+	  if (!ctx->quiet)
+	    error_at (EXPR_LOCATION (t),
+		      "statement is not a constant-expression");
+	}
+      else
+	internal_error ("unexpected expression %qE of kind %s", t,
+			get_tree_code_name (TREE_CODE (t)));
       *non_constant_p = true;
       break;
     }
diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr17.C b/gcc/testsuite/g++.dg/ext/stmtexpr17.C
new file mode 100644
index 0000000..c1640e4
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/stmtexpr17.C
@@ -0,0 +1,9 @@
+// PR c++/64701
+// { dg-options "" }
+
+enum { A };
+void
+foo ()
+{
+  int x = ({ do {} while (0); A; });
+}

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]