summaryrefslogtreecommitdiff
path: root/gcc/cp
diff options
context:
space:
mode:
authorManuel López-Ibáñez <manu@gcc.gnu.org>2008-02-14 18:11:04 -0500
committerJason Merrill <jason@gcc.gnu.org>2008-02-14 18:11:04 -0500
commit8c95264b5cfb3f385f0929b6ff90f4c8d9b94905 (patch)
treee38dc9a61c36b8f7994dae4ac12fe990e88f1885 /gcc/cp
parent101e174d2c7f1d97a276cf951bcc6d55ecbcabdd (diff)
downloadgcc-8c95264b5cfb3f385f0929b6ff90f4c8d9b94905.tar.gz
re PR c++/5645 (gcc warns that pure virtual class not explicitly initialized)
PR c++/5645 PR c++/11159 * class.c (type_has_user_nondefault_constructor): New fn. * cp-tree.h: Declare it. * init.c (emit_mem_initializers): Use it for -W warning about missing base initializer. Co-Authored-By: Jason Merrill <jason@redhat.com> From-SVN: r132324
Diffstat (limited to 'gcc/cp')
-rw-r--r--gcc/cp/ChangeLog10
-rw-r--r--gcc/cp/class.c22
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/init.c9
4 files changed, 38 insertions, 4 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 275ca4b1aeb..36355125b41 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,13 @@
+2008-02-14 Manuel Lopez-Ibanez <manu@gcc.gnu.org>
+ Jason Merrill <jason@redhat.com>
+
+ PR c++/5645
+ PR c++/11159
+ * class.c (type_has_user_nondefault_constructor): New fn.
+ * cp-tree.h: Declare it.
+ * init.c (emit_mem_initializers): Use it for -W warning about
+ missing base initializer.
+
2008-02-14 Paolo Carlini <pcarlini@suse.de>
PR c++/28743
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index a5456c23324..1a76816c229 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -4039,6 +4039,28 @@ clone_constructors_and_destructors (tree t)
clone_function_decl (OVL_CURRENT (fns), /*update_method_vec_p=*/1);
}
+/* Returns true iff class T has a user-defined constructor other than
+ the default constructor. */
+
+bool
+type_has_user_nondefault_constructor (tree t)
+{
+ tree fns;
+
+ if (!TYPE_HAS_USER_CONSTRUCTOR (t))
+ return false;
+
+ for (fns = CLASSTYPE_CONSTRUCTORS (t); fns; fns = OVL_NEXT (fns))
+ {
+ tree fn = OVL_CURRENT (fns);
+ if (!DECL_ARTIFICIAL (fn)
+ && skip_artificial_parms_for (fn, DECL_ARGUMENTS (fn)) != NULL_TREE)
+ return true;
+ }
+
+ return false;
+}
+
/* Remove all zero-width bit-fields from T. */
static void
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 27892b9c0fa..81e88613ff3 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -4157,6 +4157,7 @@ extern void determine_key_method (tree);
extern void check_for_override (tree, tree);
extern void push_class_stack (void);
extern void pop_class_stack (void);
+extern bool type_has_user_nondefault_constructor (tree);
/* in cvt.c */
extern tree convert_to_reference (tree, tree, int, int, tree);
diff --git a/gcc/cp/init.c b/gcc/cp/init.c
index 040b3351472..3e6db247137 100644
--- a/gcc/cp/init.c
+++ b/gcc/cp/init.c
@@ -829,12 +829,13 @@ emit_mem_initializers (tree mem_inits)
tree subobject = TREE_PURPOSE (mem_inits);
tree arguments = TREE_VALUE (mem_inits);
- /* If these initializations are taking place in a copy
- constructor, the base class should probably be explicitly
- initialized. */
+ /* If these initializations are taking place in a copy constructor,
+ the base class should probably be explicitly initialized if there
+ is a user-defined constructor in the base class (other than the
+ default constructor, which will be called anyway). */
if (extra_warnings && !arguments
&& DECL_COPY_CONSTRUCTOR_P (current_function_decl)
- && TYPE_NEEDS_CONSTRUCTING (BINFO_TYPE (subobject)))
+ && type_has_user_nondefault_constructor (BINFO_TYPE (subobject)))
warning (OPT_Wextra, "%Jbase class %q#T should be explicitly initialized in the "
"copy constructor",
current_function_decl, BINFO_TYPE (subobject));