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
This commit is contained in:
parent
cb3c050e51
commit
0cc5ae8d62
|
@ -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.
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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" }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue