This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: C++0x Constructor Delegation take 2


> http://gcc.gnu.org/ml/gcc-patches/2007-04/msg00620.html

Thanks a lot for the submission, and I'm sorry it has taken this long to review the patch. Please do CC me on C++ patches, and ping me if a week goes by without a review.

I agree with Doug's comments.

The tests for flag_cpp0x now need to be "cxx_dialect != cxx98".

+static void
+perform_target_ctor (tree init)
+{
+  tree decl = current_class_ref;
+  tree type = current_class_type;
+
+  if (init == void_type_node)
+    init = NULL_TREE;
+
+  finish_expr_stmt (build_aggr_init (decl, init, 0));
+
+  if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
+    {
+      tree expr = build_delete (type, decl, sfk_complete_destructor,
+			   LOOKUP_NONVIRTUAL|LOOKUP_DESTRUCTOR, 0);
+      if (expr != error_mark_node)
+	finish_eh_cleanup (expr);
+    }
+}

This assumes that we'll only do delegation for the complete constructor, which is not the case. For instance, this testcase breaks:


int c;
struct A
{
  A() { ++c; }
};

struct B: virtual A
{
  B(): B (1) {}
  B(int) {}
};

struct C: public B
{
  C(): A(), B() { }
};

int main()
{
  C cee;
  if (c > 1)
    return c;
  else if (c == 0)
    return 1;
}

We end up constructing the A subobject twice, because the B() not-in-charge constructor calls the B(int) in-charge constructor, which wrongly calls the A constructor.

Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]