+2008-05-21 Jakub Jelinek <jakub@redhat.com>
+
+ PR c++/36023
+ * cp-tree.h (check_array_initializer): New prototype.
+ * decl.c (check_array_initializer): New function.
+ (check_initializer): Call it.
+ * semantics.c (finish_compound_literal): Call it for ARRAY_TYPEs.
+
2008-05-21 Kai Tietz <kai.tietz@onevision.com>
PR/36280
extern tree groktypename (cp_decl_specifier_seq *, const cp_declarator *);
extern tree start_decl (const cp_declarator *, cp_decl_specifier_seq *, int, tree, tree, tree *);
extern void start_decl_1 (tree, bool);
+extern bool check_array_initializer (tree, tree, tree);
extern void cp_finish_decl (tree, tree, bool, tree, int);
extern void finish_decl (tree, tree, tree);
extern int cp_complete_array_type (tree *, tree, bool);
return new_init;
}
+/* Verify array initializer. Returns true if errors have been reported. */
+
+bool
+check_array_initializer (tree decl, tree type, tree init)
+{
+ tree element_type = TREE_TYPE (type);
+
+ /* The array type itself need not be complete, because the
+ initializer may tell us how many elements are in the array.
+ But, the elements of the array must be complete. */
+ if (!COMPLETE_TYPE_P (complete_type (element_type)))
+ {
+ if (decl)
+ error ("elements of array %q#D have incomplete type", decl);
+ else
+ error ("elements of array %q#T have incomplete type", type);
+ return true;
+ }
+ /* It is not valid to initialize a VLA. */
+ if (init
+ && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
+ || !TREE_CONSTANT (TYPE_SIZE (element_type))))
+ {
+ if (decl)
+ error ("variable-sized object %qD may not be initialized", decl);
+ else
+ error ("variable-sized compound literal");
+ return true;
+ }
+ return false;
+}
+
/* Verify INIT (the initializer for DECL), and record the
initialization in DECL_INITIAL, if appropriate. CLEANUP is as for
grok_reference_init.
if (TREE_CODE (type) == ARRAY_TYPE)
{
- tree element_type = TREE_TYPE (type);
-
- /* The array type itself need not be complete, because the
- initializer may tell us how many elements are in the array.
- But, the elements of the array must be complete. */
- if (!COMPLETE_TYPE_P (complete_type (element_type)))
- {
- error ("elements of array %q#D have incomplete type", decl);
- return NULL_TREE;
- }
- /* It is not valid to initialize a VLA. */
- if (init
- && ((COMPLETE_TYPE_P (type) && !TREE_CONSTANT (TYPE_SIZE (type)))
- || !TREE_CONSTANT (TYPE_SIZE (element_type))))
- {
- error ("variable-sized object %qD may not be initialized", decl);
- return NULL_TREE;
- }
+ if (check_array_initializer (decl, type, init))
+ return NULL_TREE;
}
else if (!COMPLETE_TYPE_P (type))
{
}
type = complete_type (type);
+ if (TREE_CODE (type) == ARRAY_TYPE
+ && check_array_initializer (NULL_TREE, type, compound_literal))
+ return error_mark_node;
compound_literal = reshape_init (type, compound_literal);
if (TREE_CODE (type) == ARRAY_TYPE)
cp_complete_array_type (&type, compound_literal, false);