diff mbox

C++0x PATCH for list value-initialization vs explicit constructors

Message ID 4C17D3F3.9070409@redhat.com
State New
Headers show

Commit Message

Jason Merrill June 15, 2010, 7:26 p.m. UTC
In this testcase, we are list-initializing from {}.  The FCD says that 
this means we should value-initialize the target.  We were then giving 
an error about using an explicit constructor, which doesn't apply in 
this case because we aren't using the normal list-initialization 
overload resolution rules, we're just value-initializing.

Tested x86_64-pc-linux-gnu, applying to trunk.
diff mbox

Patch

commit 4a67f791e454f5d04c8eabd0358b32e971ee0146
Author: Jason Merrill <jason@redhat.com>
Date:   Tue Jun 15 01:08:24 2010 -0400

    	* call.c (convert_like_real): Don't complain about
    	list-value-initialization from an explicit constructor.

diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index 9ce1c53..60d7333 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -4956,7 +4956,10 @@  convert_like_real (conversion *convs, tree expr, tree fn, int argnum,
 
 	/* When converting from an init list we consider explicit
 	   constructors, but actually trying to call one is an error.  */
-	if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn))
+	if (DECL_NONCONVERTING_P (convfn) && DECL_CONSTRUCTOR_P (convfn)
+	    /* Unless we're calling it for value-initialization from an
+	       empty list, since that is handled separately in 8.5.4.  */
+	    && cand->num_convs > 0)
 	  {
 	    if (complain & tf_error)
 	      error ("converting to %qT from initializer list would use "
diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist40.C b/gcc/testsuite/g++.dg/cpp0x/initlist40.C
new file mode 100644
index 0000000..f270360
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp0x/initlist40.C
@@ -0,0 +1,12 @@ 
+// { dg-options "-std=c++0x" }
+
+struct A
+{
+  explicit A(int = 42);
+};
+
+int main()
+{
+  A a1 = { };
+  A a2 = { 24 };		// { dg-error "explicit" }
+}