Hi,
in this rather old issue, we fail to include explicit constructors in
the second step of a copy-initialization and the below is rejected. I'm
not 100% sure, but using the existing comments as a guide, I think I
found the place where we wrongly set LOOKUP_ONLYCONVERTING for the
second step too. The minimal change passes testing, anyway.
Thanks,
Paolo.
Index: cp/call.c
===
--- cp/call.c (revision 225678)
+++ cp/call.c (working copy)
@@ -6437,12 +6437,14 @@ convert_like_real (conversion *convs, tree expr, t
/* Copy-initialization where the cv-unqualified version of the source
type is the same class as, or a derived class of, the class of the
destination [is treated as direct-initialization]. [dcl.init] */
- flags = LOOKUP_NORMAL|LOOKUP_ONLYCONVERTING;
+ flags = LOOKUP_NORMAL;
if (convs-user_conv_p)
/* This conversion is being done in the context of a user-defined
conversion (i.e. the second step of copy-initialization), so
don't allow any more. */
flags |= LOOKUP_NO_CONVERSION;
+ else
+ flags |= LOOKUP_ONLYCONVERTING;
if (convs-rvaluedness_matches_p)
flags |= LOOKUP_PREFER_RVALUE;
if (TREE_CODE (expr) == TARGET_EXPR
Index: testsuite/g++.dg/init/explicit3.C
===
--- testsuite/g++.dg/init/explicit3.C (revision 0)
+++ testsuite/g++.dg/init/explicit3.C (working copy)
@@ -0,0 +1,12 @@
+// PR c++/54521
+
+struct X
+{
+ X(int) {}
+ explicit X(X const ) {}
+};
+
+int main()
+{
+ X x = 1;
+}