OSDN Git Service

PR c++/51526
authorjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 19 Dec 2011 21:06:44 +0000 (21:06 +0000)
committerjason <jason@138bc75d-0d04-0410-961f-82ee72b054a4>
Mon, 19 Dec 2011 21:06:44 +0000 (21:06 +0000)
* semantics.c (build_data_member_initialization): Handle
delegating constructor.
(build_constexpr_constructor_member_initializers): Likewise.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@182499 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/semantics.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/constexpr-delegating.C [new file with mode: 0644]

index e5d0b4c..5623bcf 100644 (file)
@@ -1,5 +1,10 @@
 2011-12-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51526
+       * semantics.c (build_data_member_initialization): Handle
+       delegating constructor.
+       (build_constexpr_constructor_member_initializers): Likewise.
+
        PR c++/51553
        * cp-tree.h (LOOKUP_LIST_INIT_CTOR): Rename from
        LOOKUP_NO_COPY_CTOR_CONVERSION.
index 2788daa..ec56ab5 100644 (file)
@@ -5801,6 +5801,12 @@ build_data_member_initialization (tree t, VEC(constructor_elt,gc) **vec)
             the const_cast.  */
          member = op;
        }
+      else if (op == current_class_ptr
+              && (same_type_ignoring_top_level_qualifiers_p
+                  (TREE_TYPE (TREE_TYPE (member)),
+                   current_class_type)))
+       /* Delegating constructor.  */
+       member = op;
       else
        {
          /* We don't put out anything for an empty base.  */
@@ -5907,7 +5913,20 @@ build_constexpr_constructor_member_initializers (tree type, tree body)
   else
     gcc_assert (errorcount > 0);
   if (ok)
-    return build_constructor (type, vec);
+    {
+      if (VEC_length (constructor_elt, vec) > 0)
+       {
+         /* In a delegating constructor, return the target.  */
+         constructor_elt *ce = VEC_index (constructor_elt, vec, 0);
+         if (ce->index == current_class_ptr)
+           {
+             body = ce->value;
+             VEC_free (constructor_elt, gc, vec);
+             return body;
+           }
+       }
+      return build_constructor (type, vec);
+    }
   else
     return error_mark_node;
 }
index cf758f1..dbad293 100644 (file)
@@ -1,3 +1,8 @@
+2011-12-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51526
+       * g++.dg/cpp0x/constexpr-delegating.C: New.
+
 2011-12-19  Sandra Loosemore  <sandra@codesourcery.com>
            Tom de Vries <tom@codesourcery.com>
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/constexpr-delegating.C b/gcc/testsuite/g++.dg/cpp0x/constexpr-delegating.C
new file mode 100644 (file)
index 0000000..a020888
--- /dev/null
@@ -0,0 +1,15 @@
+// PR c++/51526
+// { dg-options -std=c++0x }
+
+const int j = 42;
+
+struct S {
+  int i;
+  constexpr S(int i) : i(i) {}
+  constexpr S() : S(j) {}
+};
+
+constexpr S s{};
+
+#define SA(X) static_assert((X),#X)
+SA(s.i == 42);