re PR c++/51553 (brace initialization and conversion operators)
authorJason Merrill <jason@redhat.com>
Mon, 19 Dec 2011 20:10:37 +0000 (15:10 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Mon, 19 Dec 2011 20:10:37 +0000 (15:10 -0500)
PR c++/51553
* call.c (add_function_candidate): Allow conversions for the copy
parm in list-initialization unless the argument is an init-list.

From-SVN: r182495

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

index d9e194978d0c6cf0f5bd305924a42d984429c806..e44008733203c023343b0e65ede42944e3eb30ae 100644 (file)
@@ -1,3 +1,9 @@
+2011-12-19  Jason Merrill  <jason@redhat.com>
+
+       PR c++/51553
+       * call.c (add_function_candidate): Allow conversions for the copy
+       parm in list-initialization unless the argument is an init-list.
+
 2011-12-19  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/51619
index dd716a40e3beb6d19003ddd373f585b3c88aaa6b..3e6db511923f8f321440098fccd2e29fdb4d886d 100644 (file)
@@ -1964,8 +1964,10 @@ add_function_candidate (struct z_candidate **candidates,
            {
              lflags |= LOOKUP_COPY_PARM;
              /* We allow user-defined conversions within init-lists, but
-                not for the copy constructor.  */
-             if (flags & LOOKUP_NO_COPY_CTOR_CONVERSION)
+                don't list-initialize the copy parm, as that would mean
+                using two levels of braces for the same type.  */
+             if ((flags & LOOKUP_NO_COPY_CTOR_CONVERSION)
+                 && BRACE_ENCLOSED_INITIALIZER_P (arg))
                lflags |= LOOKUP_NO_CONVERSION;
            }
          else
index 70c3315583252b1e13bd8fb62ceb5522569013b5..d08c3ad0831aec5ce57a5afd0c04a86f6a1c1027 100644 (file)
@@ -1,5 +1,8 @@
 2011-12-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/51553
+       * g++.dg/cpp0x/initlist64.C: New.
+
        PR c++/51228
        * c-c++-common/transparent-union-1.c: New.
 
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist64.C b/gcc/testsuite/g++.dg/cpp0x/initlist64.C
new file mode 100644 (file)
index 0000000..337e89b
--- /dev/null
@@ -0,0 +1,29 @@
+// PR c++/51553
+// { dg-options -std=c++0x }
+
+struct X
+{
+  X();
+};
+
+struct Y
+{
+  operator X() const;
+};
+
+struct Z
+{
+  explicit operator X() const;
+};
+
+X a = { Y() };
+X aa = Y();
+
+X b{ Y() };
+X bb(Y());
+
+X c = { Z() };  // { dg-error "" "" { xfail *-*-* } }
+X cc = Z();    // { dg-error "" }
+
+X d{ Z() };
+X dd( Z() );