commit 16219f7fd77e362d9aa4e717529cd42a9f126153 Author: Jason Merrill Date: Thu Oct 22 11:09:42 2009 -0700 Core issue 899 * call.c (add_function_candidate): Only permit explicit conversion ops if copy ctor was called with a single argument. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index fe74d15..4542804 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -1631,7 +1631,8 @@ add_function_candidate (struct z_candidate **candidates, parmtype = build_pointer_type (parmtype); } - if (ctype && i == 0 && DECL_COPY_CONSTRUCTOR_P (fn)) + if (ctype && i == 0 && DECL_COPY_CONSTRUCTOR_P (fn) + && (len-skip == 1)) { /* Hack: Direct-initialize copy parm (i.e. suppress LOOKUP_ONLYCONVERTING) to make explicit conversion ops diff --git a/gcc/testsuite/g++.dg/cpp0x/explicit4.C b/gcc/testsuite/g++.dg/cpp0x/explicit4.C new file mode 100644 index 0000000..74726a9 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/explicit4.C @@ -0,0 +1,17 @@ +// Negative explicit conv test. +// { dg-options "-std=c++0x" } + +struct A { + A(const A&, int = 0); // { dg-message "candidates" } +}; +struct B +{ + explicit operator A(); +}; + +int main() +{ + B b; + (A(b)); // OK + (A(b,1)); // { dg-error "no match" } +}