diff options
author | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-06 21:57:41 +0000 |
---|---|---|
committer | jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> | 2011-05-06 21:57:41 +0000 |
commit | 2349ea850e798ed2751d341287186a4560d14ef4 (patch) | |
tree | 523ded34c464561c71a40891051869504f7dc0f8 /gcc/cp | |
parent | b9f8199fcaf9760fa7aa0c3721bebeb9d86db656 (diff) | |
download | gcc-2349ea850e798ed2751d341287186a4560d14ef4.tar.gz |
PR c++/48911
* semantics.c (cxx_eval_array_reference): Handle implicit
initializers.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@173510 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cp')
-rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/cp/semantics.c | 14 |
2 files changed, 19 insertions, 1 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f19c0c1d1c7..3bc6a14680f 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2011-05-06 Jason Merrill <jason@redhat.com> + + PR c++/48911 + * semantics.c (cxx_eval_array_reference): Handle implicit + initializers. + 2011-05-06 Nathan Froyd <froydnj@codesourcery.com> * cp-tree.h (type_of_this_parm, class_of_this_parm): New functions. diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c index a2b24d3e31d..ca069f57700 100644 --- a/gcc/cp/semantics.c +++ b/gcc/cp/semantics.c @@ -6323,6 +6323,7 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, non_constant_p); tree index, oldidx; HOST_WIDE_INT i; + tree elem_type; unsigned len, elem_nchars = 1; if (*non_constant_p) return t; @@ -6335,16 +6336,27 @@ cxx_eval_array_reference (const constexpr_call *call, tree t, return t; else if (addr) return build4 (ARRAY_REF, TREE_TYPE (t), ary, index, NULL, NULL); + elem_type = TREE_TYPE (TREE_TYPE (ary)); if (TREE_CODE (ary) == CONSTRUCTOR) len = CONSTRUCTOR_NELTS (ary); else { - elem_nchars = (TYPE_PRECISION (TREE_TYPE (TREE_TYPE (ary))) + elem_nchars = (TYPE_PRECISION (elem_type) / TYPE_PRECISION (char_type_node)); len = (unsigned) TREE_STRING_LENGTH (ary) / elem_nchars; } if (compare_tree_int (index, len) >= 0) { + if (tree_int_cst_lt (index, array_type_nelts_top (TREE_TYPE (ary)))) + { + /* If it's within the array bounds but doesn't have an explicit + initializer, it's value-initialized. */ + tree val = build_value_init (elem_type, tf_warning_or_error); + return cxx_eval_constant_expression (call, val, + allow_non_constant, addr, + non_constant_p); + } + if (!allow_non_constant) error ("array subscript out of bound"); *non_constant_p = true; |