From 3e41d13b038153f299e0778130d676f6315be58b Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Sun, 30 May 1999 14:41:33 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 5 +++ gcc/cp/decl.c | 46 +++++++++------------ gcc/testsuite/g++.old-deja/g++.pt/static9.C | 27 ++++++++++++ 3 files changed, 52 insertions(+), 26 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.pt/static9.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 5307cb2d3d3..99f26355ffa 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +1999-05-30 Mark Mitchell + + * decl.c (start_decl): Move checks on initialization to ... + (cp_finish_decl): Here. Tidy formatting slightly. + 1999-05-28 Mark Mitchell * decl.c (add_binding): Don't complain about a redeclaration of a diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index edcd6083268..c30fa7caf59 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -7305,28 +7305,7 @@ start_decl (declarator, declspecs, initialized, attributes, prefix_attributes) break; default: - if (! processing_template_decl) - { - 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; - } - } - } + break; } if (initialized) @@ -7820,6 +7799,7 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) goto finish_end0; } + /* Take care of TYPE_DECLs up front. */ if (TREE_CODE (decl) == TYPE_DECL) { @@ -7850,15 +7830,13 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) DECL_CONTEXT (decl) == NULL_TREE, at_eof); goto finish_end; } + if (TREE_CODE (decl) != FUNCTION_DECL) - { - ttype = target_type (type); - } + ttype = target_type (type); if (! DECL_EXTERNAL (decl) && TREE_READONLY (decl) && TYPE_NEEDS_CONSTRUCTING (type)) { - /* Currently, GNU C++ puts constants in text space, making them impossible to initialize. In the future, one would hope for an operating system which understood the difference between @@ -7897,6 +7875,22 @@ cp_finish_decl (decl, init, asmspec_tree, need_pop, flags) 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); core_type = type; diff --git a/gcc/testsuite/g++.old-deja/g++.pt/static9.C b/gcc/testsuite/g++.old-deja/g++.pt/static9.C new file mode 100644 index 00000000000..35484a3c22a --- /dev/null +++ b/gcc/testsuite/g++.old-deja/g++.pt/static9.C @@ -0,0 +1,27 @@ +// Build don't link: +// Origin: Mark Mitchell + +template +struct S { + int i; +}; + +template +struct X { + static S s[]; +}; + +template +S X::s[] = { + { 3 } +}; + +struct Z {}; + +void f(S* s); + +void g() +{ + f (X::s); +} + -- 2.30.2