diff mbox

C++ PATCH for c++/60186 (ICE with constexpr and init-list in template)

Message ID 5307C9C5.5060403@redhat.com
State New
Headers show

Commit Message

Jason Merrill Feb. 21, 2014, 9:48 p.m. UTC
My earlier massage_init_elt patch neglected to call 
fold_non_dependent_expr before maybe_constant_init.

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

Patch

commit b77241e3be8b3eb4247d07e2f2967cbb585e08bc
Author: Jason Merrill <jason@redhat.com>
Date:   Fri Feb 21 14:37:17 2014 -0500

    	PR c++/60186
    	* typeck2.c (massage_init_elt): Call fold_non_dependent_expr_sfinae.

diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index 546b83f..8877286 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -1131,7 +1131,10 @@  massage_init_elt (tree type, tree init, tsubst_flags_t complain)
     init = TARGET_EXPR_INITIAL (init);
   /* When we defer constant folding within a statement, we may want to
      defer this folding as well.  */
-  init = maybe_constant_init (init);
+  tree t = fold_non_dependent_expr_sfinae (init, complain);
+  t = maybe_constant_value (t);
+  if (TREE_CONSTANT (t))
+    init = t;
   return init;
 }
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist7.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist7.C
new file mode 100644
index 0000000..6fea82f
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-initlist7.C
@@ -0,0 +1,7 @@ 
+// PR c++/60186
+// { dg-require-effective-target c++11 }
+
+template<typename> void foo(int i)
+{
+  constexpr int a[] = { i };	// { dg-error "" }
+}