diff options
Diffstat (limited to 'gcc/cp/init.c')
-rw-r--r-- | gcc/cp/init.c | 62 |
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. */ |