Commit 3e41d13b by Mark Mitchell Committed by Mark Mitchell

decl.c (start_decl): Move checks on initialization to ...

	* decl.c (start_decl): Move checks on initialization to ...
	(cp_finish_decl): Here.  Tidy formatting slightly.

From-SVN: r27252
parent 79f565f6
1999-05-30 Mark Mitchell <mark@codesourcery.com>
* decl.c (start_decl): Move checks on initialization to ...
(cp_finish_decl): Here. Tidy formatting slightly.
1999-05-28 Mark Mitchell <mark@codesourcery.com> 1999-05-28 Mark Mitchell <mark@codesourcery.com>
* decl.c (add_binding): Don't complain about a redeclaration of a * decl.c (add_binding): Don't complain about a redeclaration of a
......
...@@ -7305,28 +7305,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) ...@@ -7305,28 +7305,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes)
break; break;
default: default:
if (! processing_template_decl) break;
{
if (type != error_mark_node)
{
if (TYPE_SIZE (type) != NULL_TREE
&& ! TREE_CONSTANT (TYPE_SIZE (type)))
{
cp_error
("variable-sized object `%D' may not be initialized",
decl);
initialized = 0;
}
if (TREE_CODE (type) == ARRAY_TYPE
&& TYPE_SIZE (complete_type (TREE_TYPE (type))) == NULL_TREE)
{
cp_error
("elements of array `%#D' have incomplete type", decl);
initialized = 0;
}
}
}
} }
if (initialized) if (initialized)
...@@ -7820,6 +7799,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) ...@@ -7820,6 +7799,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
goto finish_end0; goto finish_end0;
} }
/* Take care of TYPE_DECLs up front. */ /* Take care of TYPE_DECLs up front. */
if (TREE_CODE (decl) == TYPE_DECL) if (TREE_CODE (decl) == TYPE_DECL)
{ {
...@@ -7850,15 +7830,13 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) ...@@ -7850,15 +7830,13 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
DECL_CONTEXT (decl) == NULL_TREE, at_eof); DECL_CONTEXT (decl) == NULL_TREE, at_eof);
goto finish_end; goto finish_end;
} }
if (TREE_CODE (decl) != FUNCTION_DECL) if (TREE_CODE (decl) != FUNCTION_DECL)
{ ttype = target_type (type);
ttype = target_type (type);
}
if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl)
&& TYPE_NEEDS_CONSTRUCTING (type)) && TYPE_NEEDS_CONSTRUCTING (type))
{ {
/* Currently, GNU C++ puts constants in text space, making them /* Currently, GNU C++ puts constants in text space, making them
impossible to initialize. In the future, one would hope for impossible to initialize. In the future, one would hope for
an operating system which understood the difference between an operating system which understood the difference between
...@@ -7897,6 +7875,22 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) ...@@ -7897,6 +7875,22 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags)
init = NULL_TREE; init = NULL_TREE;
} }
/* Check for certain invalid initializations. */
if (init)
{
if (TYPE_SIZE (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
{
cp_error ("variable-sized object `%D' may not be initialized", decl);
init = NULL_TREE;
}
if (TREE_CODE (type) == ARRAY_TYPE
&& !TYPE_SIZE (complete_type (TREE_TYPE (type))))
{
cp_error ("elements of array `%#D' have incomplete type", decl);
init = NULL_TREE;
}
}
GNU_xref_decl (current_function_decl, decl); GNU_xref_decl (current_function_decl, decl);
core_type = type; core_type = type;
......
// Build don't link:
// Origin: Mark Mitchell <mark@codesourcery.com>
template <class T>
struct S {
int i;
};
template <class T>
struct X {
static S<T> s[];
};
template <class T>
S<T> X<T>::s[] = {
{ 3 }
};
struct Z {};
void f(S<Z>* s);
void g()
{
f (X<Z>::s);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment