diff mbox

C++ PATCH for c++/66921 (ICE with array in template)

Message ID 5679C2FA.7050309@redhat.com
State New
Headers show

Commit Message

Jason Merrill Dec. 22, 2015, 9:39 p.m. UTC
An earlier patch of mine to prevent confusing array length deduction 
with a PMF constant was over-zealous; we should allow deduction from an 
already-deduced array type.

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

Patch

commit 90ff39cf3d376c2359e6ecf9dc187907682a5f2a
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Dec 21 15:28:42 2015 -0500

    	PR c++/66921
    	* decl.c (cp_complete_array_type): Allow an initializer that
    	already has array type.

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index a14062b..af5f265 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -7479,7 +7479,8 @@  cp_complete_array_type (tree *ptype, tree initial_value, bool do_default)
 
   /* Don't get confused by a CONSTRUCTOR for some other type.  */
   if (initial_value && TREE_CODE (initial_value) == CONSTRUCTOR
-      && !BRACE_ENCLOSED_INITIALIZER_P (initial_value))
+      && !BRACE_ENCLOSED_INITIALIZER_P (initial_value)
+      && TREE_CODE (TREE_TYPE (initial_value)) != ARRAY_TYPE)
     return 1;
 
   if (initial_value)
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-array14.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-array14.C
new file mode 100644
index 0000000..b8eb084
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/constexpr-array14.C
@@ -0,0 +1,9 @@ 
+// PR c++/66921
+// { dg-do compile { target c++11 } }
+
+template<typename T>
+struct Holder {
+  constexpr static const int array[] = { 1, 2, 3 };
+  enum {F = array[0]};
+};
+class HI: public Holder<int> {};