From 0cc5ae8d62ce64803914496b45b817f27813cff2 Mon Sep 17 00:00:00 2001 From: Jason Merrill Date: Sat, 16 Mar 2013 22:36:08 -0400 Subject: [PATCH] DR 1518 PR c++/54835 DR 1518 PR c++/54835 * call.c (convert_like_real): Check for explicit constructors even for value-initialization. From-SVN: r196732 --- gcc/cp/ChangeLog | 5 +++++ gcc/cp/call.c | 25 +++++++++++-------------- gcc/testsuite/g++.dg/cpp0x/initlist40.C | 3 ++- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 45c5d2887ab..70a71beddf0 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,5 +1,10 @@ 2013-03-16 Jason Merrill + DR 1518 + PR c++/54835 + * call.c (convert_like_real): Check for explicit constructors + even for value-initialization. + PR c++/54946 * pt.c (convert_nontype_argument): Handle invalid pointer. diff --git a/gcc/cp/call.c b/gcc/cp/call.c index 530835b87c8..e40c45fb871 100644 --- a/gcc/cp/call.c +++ b/gcc/cp/call.c @@ -5856,6 +5856,17 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, tree convfn = cand->fn; unsigned i; + /* 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) + /* Unless this is for direct-list-initialization. */ + && !(BRACE_ENCLOSED_INITIALIZER_P (expr) + && CONSTRUCTOR_IS_DIRECT_INIT (expr))) + { + error ("converting to %qT from initializer list would use " + "explicit constructor %qD", totype, convfn); + } + /* If we're initializing from {}, it's value-initialization. */ if (BRACE_ENCLOSED_INITIALIZER_P (expr) && CONSTRUCTOR_NELTS (expr) == 0 @@ -5874,20 +5885,6 @@ convert_like_real (conversion *convs, tree expr, tree fn, int argnum, expr = mark_rvalue_use (expr); - /* 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) - /* Unless this is for direct-list-initialization. */ - && !(BRACE_ENCLOSED_INITIALIZER_P (expr) - && CONSTRUCTOR_IS_DIRECT_INIT (expr)) - /* 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) - { - error ("converting to %qT from initializer list would use " - "explicit constructor %qD", totype, convfn); - } - /* Set user_conv_p on the argument conversions, so rvalue/base handling knows not to allow any more UDCs. */ for (i = 0; i < cand->num_convs; ++i) diff --git a/gcc/testsuite/g++.dg/cpp0x/initlist40.C b/gcc/testsuite/g++.dg/cpp0x/initlist40.C index f2703602c9e..8cf36be1ca1 100644 --- a/gcc/testsuite/g++.dg/cpp0x/initlist40.C +++ b/gcc/testsuite/g++.dg/cpp0x/initlist40.C @@ -1,3 +1,4 @@ +// PR c++/54835, DR 1518 // { dg-options "-std=c++0x" } struct A @@ -7,6 +8,6 @@ struct A int main() { - A a1 = { }; + A a1 = { }; // { dg-error "explicit" } A a2 = { 24 }; // { dg-error "explicit" } } -- 2.30.2