Patchwork C++ PATCH for c++/51714 (ICE with statement-expression in c++11 mode)

login
register
mail settings
Submitter Jason Merrill
Date Jan. 12, 2012, 10:05 p.m.
Message ID <4F0F5924.20905@redhat.com>
Download mbox | patch
Permalink /patch/135693/
State New
Headers show

Comments

Jason Merrill - Jan. 12, 2012, 10:05 p.m.
This full-expression is potentially constant because the LHS is, but we 
can't fold_non_constant_expr the RHS because it involves a 
statement-expression.  So let's treat it as value-dependent to avoid 
trying to fold it.

Tested x86_64-pc-linux-gnu, applying to trunk.

Patch

commit 3b2ed7d426c6f7f2b0c5403c98245c5fef4006be
Author: Jason Merrill <jason@redhat.com>
Date:   Thu Jan 12 14:30:31 2012 -0500

    	PR c++/51714
    	* pt.c (value_dependent_expression_p): Treat STMT_EXPR as
    	value-dependent.

diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 97a9294..f2b4c8e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -19526,6 +19526,11 @@  value_dependent_expression_p (tree expression)
 	return false;
       }
 
+    case STMT_EXPR:
+      /* Treat a GNU statement expression as dependent to avoid crashing
+	 under fold_non_dependent_expr; it can't be constant.  */
+      return true;
+
     default:
       /* A constant expression is value-dependent if any subexpression is
 	 value-dependent.  */
diff --git a/gcc/testsuite/g++.dg/ext/stmtexpr14.C b/gcc/testsuite/g++.dg/ext/stmtexpr14.C
new file mode 100644
index 0000000..5f3ff0d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/ext/stmtexpr14.C
@@ -0,0 +1,12 @@ 
+// PR c++/51714
+
+template <typename T>
+void Foo()
+{
+  true || !__extension__ ({ int verbose = 2; verbose <= 3; });
+}
+
+int main()
+{
+  Foo<int>();
+}