aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/init.c
diff options
context:
space:
mode:
authorAlexandre Oliva <aoliva@redhat.com>2002-05-14 17:20:47 +0000
committerAlexandre Oliva <aoliva@gcc.gnu.org>2002-05-14 17:20:47 +0000
commit94e6e4c4f3d7533ab1de7b709e3b3305d3d8e52d (patch)
tree8e6a21c939257492f2f1761473f122f6de4c33dd /gcc/cp/init.c
parente5f5feea65f904d95c6f7aded34f8d2f447141e9 (diff)
downloadgcc-94e6e4c4f3d7533ab1de7b709e3b3305d3d8e52d.zip
gcc-94e6e4c4f3d7533ab1de7b709e3b3305d3d8e52d.tar.gz
gcc-94e6e4c4f3d7533ab1de7b709e3b3305d3d8e52d.tar.bz2
cp-tree.h (struct lang_type): Added non_zero_init.
* cp-tree.h (struct lang_type): Added non_zero_init. (CLASS_NON_ZERO_INIT_P): New macro. (zero_init_p, force_store_init_value, build_forced_zero_init): Declare. * class.c (check_field_decls): Test non_zero_init. * cvt.c (convert_to_pointer_force): Use cp_convert_to_pointer for zero-to-NULL conversions. * decl.c (obscure_complex_init): Don't reset DECL_INITIAL of a type that needs zero-initialization without zeros. (check_initializer_decl): Compute zero-initializer for types that require a non-trivial one. * init.c (build_forced_zero_init): New function. (build_default_init): Use it. * tree.c (zero_init_p): New function. * typeck2.c (force_store_init_value): New function. (process_init_constructor): Create non-trivial zero-initializers for array members and class fields. From-SVN: r53461
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r--gcc/cp/init.c62
1 files changed, 40 insertions, 22 deletions
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 49ecf7c..9827307 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -1,6 +1,6 @@
/* Handle initialization things in C++.
Copyright (C) 1987, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
- 1999, 2000, 2001 Free Software Foundation, Inc.
+ 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
Contributed by Michael Tiemann (tiemann@cygnus.com)
This file is part of GNU CC.
@@ -156,6 +156,44 @@ initialize_vtbl_ptrs (addr)
dfs_marked_real_bases_queue_p, type);
}
+/* Types containing pointers to data members cannot be
+ zero-initialized with zeros, because the NULL value for such
+ pointers is -1.
+
+ TYPE is a type that requires such zero initialization. The
+ returned value is the initializer. */
+
+tree
+build_forced_zero_init (type)
+ tree type;
+{
+ tree init = NULL;
+
+ if (AGGREGATE_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type))
+ {
+ /* This is a default initialization of an aggregate, but not one of
+ non-POD class type. We cleverly notice that the initialization
+ rules in such a case are the same as for initialization with an
+ empty brace-initialization list. */
+ init = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, NULL_TREE);
+ }
+ else if (TREE_CODE (type) == REFERENCE_TYPE)
+ /* --if T is a reference type, no initialization is performed. */
+ return NULL_TREE;
+ else
+ {
+ init = integer_zero_node;
+
+ if (TREE_CODE (type) == ENUMERAL_TYPE)
+ /* We must make enumeral types the right type. */
+ init = fold (build1 (NOP_EXPR, type, init));
+ }
+
+ init = digest_init (type, init, 0);
+
+ return init;
+}
+
/* [dcl.init]:
To default-initialize an object of type T means:
@@ -182,28 +220,8 @@ build_default_init (type)
anything with a CONSTRUCTOR for arrays here, as that would imply
copy-initialization. */
return NULL_TREE;
- else if (AGGREGATE_TYPE_P (type) && !TYPE_PTRMEMFUNC_P (type))
- {
- /* This is a default initialization of an aggregate, but not one of
- non-POD class type. We cleverly notice that the initialization
- rules in such a case are the same as for initialization with an
- empty brace-initialization list. */
- init = build (CONSTRUCTOR, NULL_TREE, NULL_TREE, NULL_TREE);
- }
- else if (TREE_CODE (type) == REFERENCE_TYPE)
- /* --if T is a reference type, no initialization is performed. */
- return NULL_TREE;
- else
- {
- init = integer_zero_node;
-
- if (TREE_CODE (type) == ENUMERAL_TYPE)
- /* We must make enumeral types the right type. */
- init = fold (build1 (NOP_EXPR, type, init));
- }
- init = digest_init (type, init, 0);
- return init;
+ return build_forced_zero_init (type);
}
/* Subroutine of emit_base_init. */