void
check_narrowing (tree type, tree init)
{
- tree ftype = TREE_TYPE (init);
+ tree ftype = unlowered_expr_type (init);
bool ok = true;
REAL_VALUE_TYPE d;
bool was_decl = false;
}
if (!ok)
- permerror (input_location, "narrowing conversion of %qE to %qT inside { }",
- init, type);
+ permerror (input_location, "narrowing conversion of %qE from %qT to %qT inside { }",
+ init, ftype, type);
}
/* Process the initializer INIT for a variable of type TYPE, emitting
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
{
tree next;
+ tree type;
if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field))
{
if (TREE_CODE (field) != FIELD_DECL || DECL_ARTIFICIAL (field))
continue;
+ /* If this is a bitfield, first convert to the declared type. */
+ type = TREE_TYPE (field);
+ if (DECL_BIT_FIELD_TYPE (field))
+ type = DECL_BIT_FIELD_TYPE (field);
+
if (idx < VEC_length (constructor_elt, CONSTRUCTOR_ELTS (init)))
{
constructor_elt *ce = VEC_index (constructor_elt,
}
gcc_assert (ce->value);
- next = digest_init_r (TREE_TYPE (field), ce->value, true);
+ next = digest_init_r (type, ce->value, true);
++idx;
}
else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field)))
continue;
}
+ /* If this is a bitfield, now convert to the lowered type. */
+ if (type != TREE_TYPE (field))
+ next = cp_convert_and_check (TREE_TYPE (field), next);
flags |= picflag_from_initializer (next);
CONSTRUCTOR_APPEND_ELT (v, field, next);
}
--- /dev/null
+// PR c++/37932
+// { dg-options "-std=c++0x" }
+
+typedef enum { AA=1, BB=2 } my_enum;
+
+typedef struct { my_enum a:4 ; unsigned b:28; } stru;
+
+void foo (char c, my_enum x, int i)
+{
+ char arr[2] = {c+'0', 0}; // { dg-error "narrowing" }
+ stru s = {x,0};
+}