diff options
Diffstat (limited to 'gcc/cp/decl.c')
| -rw-r--r-- | gcc/cp/decl.c | 101 |
1 files changed, 60 insertions, 41 deletions
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index bccb438..e005d63 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -4111,12 +4111,17 @@ maybe_deduce_size_from_array_init (tree decl, tree init) do_default); if (failure == 1) - error ("initializer fails to determine size of %qD", decl); - - if (failure == 2) + { + error ("initializer fails to determine size of %qD", decl); + TREE_TYPE (decl) = error_mark_node; + } + else if (failure == 2) { if (do_default) - error ("array size missing in %qD", decl); + { + error ("array size missing in %qD", decl); + TREE_TYPE (decl) = error_mark_node; + } /* If a `static' var's size isn't known, make it extern as well as static, so it does not get allocated. If it's not `static', then don't mark it extern; finish_incomplete_decl @@ -4124,9 +4129,11 @@ maybe_deduce_size_from_array_init (tree decl, tree init) else if (!pedantic && TREE_STATIC (decl) && !TREE_PUBLIC (decl)) DECL_EXTERNAL (decl) = 1; } - - if (failure == 3) - error ("zero-size array %qD", decl); + else if (failure == 3) + { + error ("zero-size array %qD", decl); + TREE_TYPE (decl) = error_mark_node; + } cp_apply_type_quals_to_decl (cp_type_quals (TREE_TYPE (decl)), decl); @@ -4140,7 +4147,17 @@ maybe_deduce_size_from_array_init (tree decl, tree init) static void layout_var_decl (tree decl) { - tree type = TREE_TYPE (decl); + tree type; + + if (TREE_STATIC (decl) + && !DECL_ARTIFICIAL (decl) + && current_function_decl + && DECL_CONTEXT (decl) == current_function_decl) + push_local_name (decl); + + type = TREE_TYPE (decl); + if (type == error_mark_node) + return; /* If we haven't already layed out this declaration, do so now. Note that we must not call complete type for an external object @@ -4186,12 +4203,6 @@ layout_var_decl (tree decl) else error ("storage size of %qD isn't constant", decl); } - - if (TREE_STATIC (decl) - && !DECL_ARTIFICIAL (decl) - && current_function_decl - && DECL_CONTEXT (decl) == current_function_decl) - push_local_name (decl); } /* If a local static variable is declared in an inline function, or if @@ -4714,6 +4725,8 @@ check_initializer (tree decl, tree init, int flags, tree *cleanup) array size from the initializer. */ maybe_deduce_size_from_array_init (decl, init); type = TREE_TYPE (decl); + if (type == error_mark_node) + return NULL_TREE; if (TYPE_HAS_CONSTRUCTOR (type) || TYPE_NEEDS_CONSTRUCTING (type)) { @@ -4977,6 +4990,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, const char *asmspec = NULL; int was_readonly = 0; bool var_definition_p = false; + int saved_processing_template_decl; if (decl == error_mark_node) return; @@ -4988,9 +5002,16 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, } gcc_assert (TREE_CODE (decl) != RESULT_DECL); + /* Parameters are handled by store_parm_decls, not cp_finish_decl. */ + gcc_assert (TREE_CODE (decl) != PARM_DECL); + + type = TREE_TYPE (decl); + if (type == error_mark_node) + return; /* Assume no cleanup is required. */ cleanup = NULL_TREE; + saved_processing_template_decl = processing_template_decl; /* If a name was specified, get the string. */ if (global_scope_p (current_binding_level)) @@ -4998,51 +5019,48 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, if (asmspec_tree) asmspec = TREE_STRING_POINTER (asmspec_tree); - if (init && TREE_CODE (init) == NAMESPACE_DECL) - { - error ("cannot initialize %qD to namespace %qD", decl, init); - init = NULL_TREE; - } - if (current_class_type && CP_DECL_CONTEXT (decl) == current_class_type && TYPE_BEING_DEFINED (current_class_type) && (DECL_INITIAL (decl) || init)) DECL_INITIALIZED_IN_CLASS_P (decl) = 1; - type = TREE_TYPE (decl); - - if (type == error_mark_node) - goto finish_end; - if (processing_template_decl) { + bool type_dependent_p; + /* Add this declaration to the statement-tree. */ if (at_function_scope_p ()) add_decl_expr (decl); - if (init) + type_dependent_p = dependent_type_p (type); + + if (init && init_const_expr_p) { - DECL_INITIAL (decl) = init; - if (init_const_expr_p) - { - DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; - if (DECL_INTEGRAL_CONSTANT_VAR_P (decl)) - TREE_CONSTANT (decl) = 1; - } + DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = 1; + if (DECL_INTEGRAL_CONSTANT_VAR_P (decl)) + TREE_CONSTANT (decl) = 1; } - if (TREE_CODE (decl) == VAR_DECL - && !DECL_PRETTY_FUNCTION_P (decl) - && !dependent_type_p (TREE_TYPE (decl))) - maybe_deduce_size_from_array_init (decl, init); + if (!init + || !DECL_CLASS_SCOPE_P (decl) + || !DECL_INTEGRAL_CONSTANT_VAR_P (decl) + || type_dependent_p + || value_dependent_expression_p (init)) + { + if (init) + DECL_INITIAL (decl) = init; + if (TREE_CODE (decl) == VAR_DECL + && !DECL_PRETTY_FUNCTION_P (decl) + && !type_dependent_p) + maybe_deduce_size_from_array_init (decl, init); + goto finish_end; + } - goto finish_end; + init = fold_non_dependent_expr (init); + processing_template_decl = 0; } - /* Parameters are handled by store_parm_decls, not cp_finish_decl. */ - gcc_assert (TREE_CODE (decl) != PARM_DECL); - /* Take care of TYPE_DECLs up front. */ if (TREE_CODE (decl) == TYPE_DECL) { @@ -5236,6 +5254,7 @@ cp_finish_decl (tree decl, tree init, bool init_const_expr_p, push_cleanup (decl, cleanup, false); finish_end: + processing_template_decl = saved_processing_template_decl; if (was_readonly) TREE_READONLY (decl) = 1; |
