From 0a73242e1ab3ac00d8fe9a98f10732473a96dc04 Mon Sep 17 00:00:00 2001 From: Paolo Carlini Date: Fri, 10 Jul 2015 22:56:35 +0000 Subject: [PATCH] re PR c++/54521 (g++ fails to call explicit constructors in the second step of copy initialization) /cp 2015-07-10 Paolo Carlini PR c++/54521 * call.c (convert_like_real): Do not set LOOKUP_ONLYCONVERTING for the second step of copy-initialization. /testsuite 2015-07-10 Paolo Carlini PR c++/54521 * g++.dg/init/explicit3.C: New. From-SVN: r225705 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/call.c | 4 +++- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/init/explicit3.C | 12 ++++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/init/explicit3.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 130e358..9d9e0c1 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2015-07-10 Paolo Carlini + + PR c++/54521 + * call.c (convert_like_real): Do not set LOOKUP_ONLYCONVERTING for + the second step of copy-initialization. + 2015-07-10 Jason Merrill * pt.c (find_parameter_packs_r): Handle variable templates. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 4da1072..07d6f0e 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -6437,12 +6437,14 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, /* 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 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 44d391b..dde2803 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2015-07-10 Paolo Carlini + + PR c++/54521 + * g++.dg/init/explicit3.C: New. + 2015-07-10 H.J. Lu PR target/66819 diff --git a/gcc/testsuite/g++.dg/init/explicit3.C b/gcc/testsuite/g++.dg/init/explicit3.C new file mode 100644 index 0000000..c5d4e0d --- /dev/null +++ b/gcc/testsuite/g++.dg/init/explicit3.C @@ -0,0 +1,12 @@ +// PR c++/54521 + +struct X +{ + X(int) {} + explicit X(X const &) {} +}; + +int main() +{ + X x = 1; +} -- 2.7.4