aboutsummaryrefslogtreecommitdiff
path: root/gcc/cp/typeck2.c
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/cp/typeck2.c')
-rw-r--r--gcc/cp/typeck2.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c
index bf0ff6b..207dd99 100644
--- a/gcc/cp/typeck2.c
+++ b/gcc/cp/typeck2.c
@@ -650,7 +650,7 @@ store_init_value (tree decl, tree init)
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;
@@ -704,8 +704,8 @@ check_narrowing (tree type, tree init)
}
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
@@ -993,6 +993,7 @@ process_init_constructor_record (tree type, tree init)
for (field = TYPE_FIELDS (type); field; field = TREE_CHAIN (field))
{
tree next;
+ tree type;
if (!DECL_NAME (field) && DECL_C_BIT_FIELD (field))
{
@@ -1004,6 +1005,11 @@ process_init_constructor_record (tree type, tree init)
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,
@@ -1024,7 +1030,7 @@ process_init_constructor_record (tree type, tree init)
}
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)))
@@ -1068,6 +1074,9 @@ process_init_constructor_record (tree type, tree init)
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);
}