]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
call.c (build_new_method_call_1): Handle aggregate initialization.
authorJason Merrill <jason@redhat.com>
Fri, 2 Dec 2011 02:57:40 +0000 (21:57 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 2 Dec 2011 02:57:40 +0000 (21:57 -0500)
* call.c (build_new_method_call_1): Handle aggregate initialization.
* tree.c (stabilize_init): Handle CONSTRUCTOR.

From-SVN: r181902

gcc/cp/ChangeLog
gcc/cp/call.c
gcc/cp/tree.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/cpp0x/initlist61.C [new file with mode: 0644]

index 0c118f16aa17a1c4677b0ed925f523d8b5a972e3..201f5efb603996e6e0bf3b5483392565582f8226 100644 (file)
@@ -1,3 +1,8 @@
+2011-12-01  Jason Merrill  <jason@redhat.com>
+
+       * call.c (build_new_method_call_1): Handle aggregate initialization.
+       * tree.c (stabilize_init): Handle CONSTRUCTOR.
+
 2011-12-01  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/51326
index e7bbf0a1d8bfb91236285cf145695db8331fe7a7..548a36bf8e502f2b51984152041f70d02cd587e9 100644 (file)
@@ -7198,6 +7198,7 @@ build_new_method_call_1 (tree instance, tree fns, VEC(tree,gc) **args,
       && CONSTRUCTOR_IS_DIRECT_INIT (VEC_index (tree, *args, 0)))
     {
       tree init_list = VEC_index (tree, *args, 0);
+      tree init = NULL_TREE;
 
       gcc_assert (VEC_length (tree, *args) == 1
                  && !(flags & LOOKUP_ONLYCONVERTING));
@@ -7209,8 +7210,16 @@ build_new_method_call_1 (tree instance, tree fns, VEC(tree,gc) **args,
       if (CONSTRUCTOR_NELTS (init_list) == 0
          && TYPE_HAS_DEFAULT_CONSTRUCTOR (basetype)
          && !processing_template_decl)
+       init = build_value_init (basetype, complain);
+
+      /* If BASETYPE is an aggregate, we need to do aggregate
+        initialization.  */
+      else if (CP_AGGREGATE_TYPE_P (basetype))
+       init = digest_init (basetype, init_list, complain);
+
+      if (init)
        {
-         tree ob, init = build_value_init (basetype, complain);
+         tree ob;
          if (integer_zerop (instance_ptr))
            return get_target_expr_sfinae (init, complain);
          ob = build_fold_indirect_ref (instance_ptr);
@@ -7219,6 +7228,7 @@ build_new_method_call_1 (tree instance, tree fns, VEC(tree,gc) **args,
          return init;
        }
 
+      /* Otherwise go ahead with overload resolution.  */
       add_list_candidates (fns, first_mem_arg, init_list,
                           basetype, explicit_targs, template_only,
                           conversion_path, access_binfo, flags, &candidates);
index d206fd2ec2480cf40c6bc9392a707222e1ad5835..8d179d8d2a08efb4f60cf84765eef805d4ae57b2 100644 (file)
@@ -3337,6 +3337,7 @@ stabilize_init (tree init, tree *initp)
 
   if (TREE_CODE (t) == INIT_EXPR
       && TREE_CODE (TREE_OPERAND (t, 1)) != TARGET_EXPR
+      && TREE_CODE (TREE_OPERAND (t, 1)) != CONSTRUCTOR
       && TREE_CODE (TREE_OPERAND (t, 1)) != AGGR_INIT_EXPR)
     {
       TREE_OPERAND (t, 1) = stabilize_expr (TREE_OPERAND (t, 1), initp);
index 084ef44332003a7364aaed9a82a74e04410ae06a..cd9e27e77f8035219653464e7147a87d4d42c324 100644 (file)
@@ -1,3 +1,7 @@
+2011-12-01  Jason Merrill  <jason@redhat.com>
+
+       * g++.dg/cpp0x/initlist61.C: New.
+
 2011-12-01  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/51326
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist61.C b/gcc/testsuite/g++.dg/cpp0x/initlist61.C
new file mode 100644 (file)
index 0000000..28eccc2
--- /dev/null
@@ -0,0 +1,9 @@
+// { dg-do compile { target c++11 } }
+
+struct N { N(int); };
+struct A { N i,j; };
+
+int main()
+{
+  A* ap = new A{1,2};
+}