aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2013-03-16 22:36:08 -0400
committerJason Merrill <jason@gcc.gnu.org>2013-03-16 22:36:08 -0400
commit0cc5ae8d62ce64803914496b45b817f27813cff2 (patch)
tree94fd27a2297724703a28eb97885a0cee7748efea
parentcb3c050e515c697b2b69991ce9c7a770e301ac92 (diff)
downloadgcc-0cc5ae8d62ce64803914496b45b817f27813cff2.zip
gcc-0cc5ae8d62ce64803914496b45b817f27813cff2.tar.gz
gcc-0cc5ae8d62ce64803914496b45b817f27813cff2.tar.bz2
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
-rw-r--r--gcc/cp/ChangeLog5
-rw-r--r--gcc/cp/call.c25
-rw-r--r--gcc/testsuite/g++.dg/cpp0x/initlist40.C3
3 files changed, 18 insertions, 15 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 45c5d28..70a71be 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,10 @@
2013-03-16 Jason Merrill <jason@redhat.com>
+ 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 530835b..e40c45f 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 f270360..8cf36be 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" }
}