This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH for bogus code-generation on base-classinitialization
- To: egcs-patches at egcs dot cygnus dot com
- Subject: C++ PATCH for bogus code-generation on base-classinitialization
- From: mark at codesourcery dot com
- Date: Wed, 16 Jun 1999 17:56:44 -0700
- Organization: CodeSourcery, LLC
Here we were doing too much work, and as a result generating bogus
code. Removing the extra work makes the right thing happen.
Installed on the mainline and on the branch.
--
Mark Mitchell mark@codesourcery.com
CodeSourcery, LLC http://www.codesourcery.com
1999-06-16 Mark Mitchell <mark@codesourcery.com>
* method.c (do_build_copy_constructor): Simplify.
Index: testsuite/g++.old-deja/g++.other/copy2.C
===================================================================
RCS file: copy2.C
diff -N copy2.C
--- /dev/null Sat Dec 5 20:30:03 1998
+++ copy2.C Wed Jun 16 17:18:41 1999
@@ -0,0 +1,21 @@
+// Origin: Mark Mitchell <mark@codesourcery.com>
+
+int i;
+
+struct B {
+ B () {}
+ B (B&) { i = 1; }
+ B (const B&) { i = 2; }
+};
+
+struct D : public B {
+ D () {}
+};
+
+int main ()
+{
+ D d;
+ D d2 (d);
+ if (i != 2)
+ return 1;
+}
Index: testsuite/cp/method.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/cp/method.c,v
retrieving revision 1.102
diff -u -p -r1.102 method.c
--- method.c 1999/06/06 11:06:27 1.102
+++ method.c 1999/06/17 00:18:57
@@ -2231,42 +2231,21 @@ do_build_copy_constructor (fndecl)
tree binfos = TYPE_BINFO_BASETYPES (current_class_type);
int i;
+ /* Initialize all the base-classes. */
for (t = CLASSTYPE_VBASECLASSES (current_class_type); t;
t = TREE_CHAIN (t))
- {
- tree basetype = BINFO_TYPE (t);
- tree p = convert_to_reference
- (build_reference_type (basetype), parm,
- CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
- p = convert_from_reference (p);
-
- if (p == error_mark_node)
- cp_error ("in default copy constructor");
- else
- current_base_init_list = tree_cons (basetype,
- p, current_base_init_list);
- }
-
+ current_base_init_list
+ = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
for (i = 0; i < n_bases; ++i)
{
- tree p, basetype = TREE_VEC_ELT (binfos, i);
- if (TREE_VIA_VIRTUAL (basetype))
+ t = TREE_VEC_ELT (binfos, i);
+ if (TREE_VIA_VIRTUAL (t))
continue;
- basetype = BINFO_TYPE (basetype);
- p = convert_to_reference
- (build_reference_type (basetype), parm,
- CONV_IMPLICIT|CONV_CONST, LOOKUP_COMPLAIN, NULL_TREE);
-
- if (p == error_mark_node)
- cp_error ("in default copy constructor");
- else
- {
- p = convert_from_reference (p);
- current_base_init_list = tree_cons (basetype,
- p, current_base_init_list);
- }
+ current_base_init_list
+ = tree_cons (BINFO_TYPE (t), parm, current_base_init_list);
}
+
for (; fields; fields = TREE_CHAIN (fields))
{
tree init, t;