From: Jason Merrill Date: Fri, 14 Nov 2008 05:24:59 +0000 (-0500) Subject: re PR c++/37932 (narrowing conversion with -std=c++0x) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=23b812615847175f7aed60ed2571638af43f2d95;p=thirdparty%2Fgcc.git re PR c++/37932 (narrowing conversion with -std=c++0x) PR c++/37932 * typeck2.c (process_init_constructor_record): Update bitfield handling. From-SVN: r141846 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 528957c71f05..96084a112427 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2008-11-13 Jason Merrill + + PR c++/37932 + * typeck2.c (process_init_constructor_record): Update bitfield + handling. + 2008-11-12 Jason Merrill PR c++/38007 diff --git a/gcc/cp/typeck2.c b/gcc/cp/typeck2.c index 9ab0c65e88bd..a2fce0c75968 100644 --- a/gcc/cp/typeck2.c +++ b/gcc/cp/typeck2.c @@ -888,6 +888,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)) { @@ -899,6 +900,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, @@ -919,7 +925,7 @@ process_init_constructor_record (tree type, tree init) } gcc_assert (ce->value); - next = digest_init (TREE_TYPE (field), ce->value); + next = digest_init (type, ce->value); ++idx; } else if (TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (field))) @@ -962,6 +968,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 = convert_and_check (TREE_TYPE (field), next); flags |= picflag_from_initializer (next); CONSTRUCTOR_APPEND_ELT (v, field, next); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a131a9b06da6..b37c568c2560 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2008-11-13 Jason Merrill + + PR c++/37932 + * g++.dg/conversion/bitfield11.C: New test. + 2008-11-12 Jason Merrill PR c++/38007 diff --git a/gcc/testsuite/g++.dg/conversion/bitfield11.C b/gcc/testsuite/g++.dg/conversion/bitfield11.C new file mode 100644 index 000000000000..e36539c64b5e --- /dev/null +++ b/gcc/testsuite/g++.dg/conversion/bitfield11.C @@ -0,0 +1,8 @@ +// Make sure that digest_init converts to the declared type of the +// bitfield, not just the lowered type. + +enum E { EA, EB }; + +struct A { E e: 8; }; + +A a = { 0 }; // { dg-error "invalid conversion" }