aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2014-12-04 15:37:30 -0500
committerJason Merrill <jason@gcc.gnu.org>2014-12-04 15:37:30 -0500
commitef9f382ca52a80bb8575d73d7cc8d3ddbf5f7ad7 (patch)
tree49c4e37adfdcdda395e897cca82fb1cbe690ac32 /gcc
parenta1408b7e414610b8d7e2d3d6784746cff578178f (diff)
downloadgcc-ef9f382ca52a80bb8575d73d7cc8d3ddbf5f7ad7.zip
gcc-ef9f382ca52a80bb8575d73d7cc8d3ddbf5f7ad7.tar.gz
gcc-ef9f382ca52a80bb8575d73d7cc8d3ddbf5f7ad7.tar.bz2
re PR c++/64029 (const int (&in)[]{1,2,3,4,5}; results in internal compiler error: Segmentation fault)
PR c++/64029 * decl.c (grok_reference_init): Complete array type. From-SVN: r218402
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog3
-rw-r--r--gcc/cp/decl.c17
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist89.C4
3 files changed, 23 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 2db8bd7..361e634 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,8 @@
2014-12-03 Jason Merrill <jason@redhat.com>
+ PR c++/64029
+ * decl.c (grok_reference_init): Complete array type.
+
PR c++/64080
* constexpr.c (cxx_eval_store_expression): Handle non-decl store
targets.
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 2996ee6..5639b3d 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -4936,11 +4936,26 @@ grok_reference_init (tree decl, tree type, tree init, int flags)
init = build_x_compound_expr_from_list (init, ELK_INIT,
tf_warning_or_error);
- if (TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE
+ tree ttype = TREE_TYPE (type);
+ if (TREE_CODE (ttype) != ARRAY_TYPE
&& TREE_CODE (TREE_TYPE (init)) == ARRAY_TYPE)
/* Note: default conversion is only called in very special cases. */
init = decay_conversion (init, tf_warning_or_error);
+ /* check_initializer handles this for non-reference variables, but for
+ references we need to do it here or the initializer will get the
+ incomplete array type and confuse later calls to
+ cp_complete_array_type. */
+ if (TREE_CODE (ttype) == ARRAY_TYPE
+ && TYPE_DOMAIN (ttype) == NULL_TREE
+ && (BRACE_ENCLOSED_INITIALIZER_P (init)
+ || TREE_CODE (init) == STRING_CST))
+ {
+ cp_complete_array_type (&ttype, init, false);
+ if (ttype != TREE_TYPE (type))
+ type = cp_build_reference_type (ttype, TYPE_REF_IS_RVALUE (type));
+ }
+
/* Convert INIT to the reference type TYPE. This may involve the
creation of a temporary, whose lifetime must be the same as that
of the reference. If so, a DECL_EXPR for the temporary will be
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist89.C b/gcc/testsuite/g++.dg/cpp0x/initlist89.C
new file mode 100644
index 0000000..e221664
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist89.C
@@ -0,0 +1,4 @@
+// PR c++/64029
+// { dg-do compile { target c++11 } }
+
+const int (&in)[]{1,2,3,4,5};