aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/decl.c
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2011-04-25 17:51:33 -0400
committerJason Merrill <jason@gcc.gnu.org>2011-04-25 17:51:33 -0400
commitd95f258e9027e7d797bde4eace3e29ab7d9382db (patch)
tree85e95790d9e34a31798f2d73b8ff70073b0ff6ac /gcc/cp/decl.c
parent4d583bb9fcd52dfe308a438bf31433ad8f23c0d5 (diff)
downloadgcc-d95f258e9027e7d797bde4eace3e29ab7d9382db.zip
gcc-d95f258e9027e7d797bde4eace3e29ab7d9382db.tar.gz
gcc-d95f258e9027e7d797bde4eace3e29ab7d9382db.tar.bz2
re PR c++/48707 ([c++0x] ICE initializing static const int)
PR c++/48707 * decl.c (type_dependent_init_p): New. (cp_finish_decl): Check it. * pt.c (any_type_dependent_elements_p): New. * cp-tree.h: Declare it. From-SVN: r172941
Diffstat (limited to 'gcc/cp/decl.c')
-rw-r--r--gcc/cp/decl.c54
1 files changed, 45 insertions, 9 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index cf4a40e..dcd18ab 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -5701,6 +5701,36 @@ initialize_artificial_var (tree decl, VEC(constructor_elt,gc) *v)
}
/* INIT is the initializer for a variable, as represented by the
+ parser. Returns true iff INIT is type-dependent. */
+
+static bool
+type_dependent_init_p (tree init)
+{
+ if (TREE_CODE (init) == TREE_LIST)
+ /* A parenthesized initializer, e.g.: int i (3, 2); ? */
+ return any_type_dependent_elements_p (init);
+ else if (TREE_CODE (init) == CONSTRUCTOR)
+ /* A brace-enclosed initializer, e.g.: int i = { 3 }; ? */
+ {
+ VEC(constructor_elt, gc) *elts;
+ size_t nelts;
+ size_t i;
+
+ elts = CONSTRUCTOR_ELTS (init);
+ nelts = VEC_length (constructor_elt, elts);
+ for (i = 0; i < nelts; ++i)
+ if (type_dependent_init_p (VEC_index (constructor_elt,
+ elts, i)->value))
+ return true;
+ }
+ else
+ /* It must be a simple expression, e.g., int i = 3; */
+ return type_dependent_expression_p (init);
+
+ return false;
+}
+
+/* INIT is the initializer for a variable, as represented by the
parser. Returns true iff INIT is value-dependent. */
static bool
@@ -5876,19 +5906,25 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p,
template is instantiated. But, if DECL is a variable constant
then it can be used in future constant expressions, so its value
must be available. */
- if (init
- && init_const_expr_p
- && !type_dependent_p
- && decl_maybe_constant_var_p (decl)
- && !value_dependent_init_p (init))
- {
+
+ if (TREE_CODE (decl) != VAR_DECL || dependent_type_p (type))
+ /* We can't do anything if the decl has dependent type. */;
+ else if (init
+ && init_const_expr_p
+ && !type_dependent_p
+ && decl_maybe_constant_var_p (decl)
+ && !type_dependent_init_p (init)
+ && !value_dependent_init_p (init))
+ {
+ /* This variable seems to be a non-dependent constant, so process
+ its initializer. If check_initializer returns non-null the
+ initialization wasn't constant after all. */
tree init_code = check_initializer (decl, init, flags, &cleanup);
if (init_code == NULL_TREE)
init = NULL_TREE;
}
- else if (TREE_CODE (decl) == VAR_DECL
- && !DECL_PRETTY_FUNCTION_P (decl)
- && !type_dependent_p)
+ else if (!DECL_PRETTY_FUNCTION_P (decl))
+ /* Deduce array size even if the initializer is dependent. */
maybe_deduce_size_from_array_init (decl, init);
if (init)