-2009-06-01 Jason Merrill <jason@redhat.com>
+2009-06-02 Jason Merrill <jason@redhat.com>
+
+ PR c++/40308
+ PR c++/40311
+ * typeck.c (cp_build_modify_expr): Always pass init-lists to the
+ conversion code.
+ * call.c (implicit_conversion): Allow init-list conversion to scalar
+ during direct-initialization, too. Mark the conversion bad if it
+ has too many levels of braces.
+ (convert_like_real): And give a helpful error.
PR c++/40306
PR c++/40307
return build_list_conv (to, expr, flags);
/* Allow conversion from an initializer-list with one element to a
- scalar type if this is copy-initialization. Direct-initialization
- would be something like int i({1}), which is invalid. */
- if (SCALAR_TYPE_P (to) && CONSTRUCTOR_NELTS (expr) <= 1
- && (flags & LOOKUP_ONLYCONVERTING))
+ scalar type. */
+ if (SCALAR_TYPE_P (to))
{
+ int nelts = CONSTRUCTOR_NELTS (expr);
tree elt;
- if (CONSTRUCTOR_NELTS (expr) == 1)
+
+ if (nelts == 0)
+ elt = integer_zero_node;
+ else if (nelts == 1)
elt = CONSTRUCTOR_ELT (expr, 0)->value;
else
- elt = integer_zero_node;
+ elt = error_mark_node;
+
conv = implicit_conversion (to, TREE_TYPE (elt), elt,
c_cast_p, flags);
if (conv)
{
conv->check_narrowing = true;
+ if (BRACE_ENCLOSED_INITIALIZER_P (elt))
+ /* Too many levels of braces, i.e. '{{1}}'. */
+ conv->bad_p = true;
return conv;
}
}
&& convs->kind != ck_base)
{
conversion *t = convs;
+
+ /* Give a helpful error if this is bad because of excess braces. */
+ if (BRACE_ENCLOSED_INITIALIZER_P (expr)
+ && SCALAR_TYPE_P (totype)
+ && CONSTRUCTOR_NELTS (expr) > 0
+ && BRACE_ENCLOSED_INITIALIZER_P (CONSTRUCTOR_ELT (expr, 0)->value))
+ permerror (input_location, "too many braces around initializer for %qT", totype);
+
for (; t; t = convs->u.next)
{
if (t->kind == ck_user || !t->bad_p)
if (modifycode == INIT_EXPR)
{
- if (TREE_CODE (rhs) == CONSTRUCTOR)
+ if (BRACE_ENCLOSED_INITIALIZER_P (rhs))
+ /* Do the default thing. */;
+ else if (TREE_CODE (rhs) == CONSTRUCTOR)
{
+ /* Compound literal. */
if (! same_type_p (TREE_TYPE (rhs), lhstype))
/* Call convert to generate an error; see PR 11063. */
rhs = convert (lhstype, rhs);
2009-06-02 Jason Merrill <jason@redhat.com>
+ * g++.dg/cpp0x/initlist13.C: Remove expected error.
+ * g++.dg/cpp0x/initlist18.C: New.
+ * g++.dg/cpp0x/initlist19.C: New.
+
* g++.dg/cpp0x/auto14.C: New.
2009-06-02 Eric Botcazou <ebotcazou@adacore.com>