]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR c++/37932 (narrowing conversion with -std=c++0x)
authorJason Merrill <jason@redhat.com>
Fri, 14 Nov 2008 05:24:59 +0000 (00:24 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Fri, 14 Nov 2008 05:24:59 +0000 (00:24 -0500)
        PR c++/37932
        * typeck2.c (process_init_constructor_record): Update bitfield
        handling.

From-SVN: r141846

gcc/cp/ChangeLog
gcc/cp/typeck2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/conversion/bitfield11.C [new file with mode: 0644]

index 528957c71f05c61c68fcffebab870b59b1b4dad3..96084a112427c92d73d5e5cc6d1eb8997b6770f8 100644 (file)
@@ -1,3 +1,9 @@
+2008-11-13  Jason Merrill  <jason@redhat.com>
+
+       PR c++/37932
+       * typeck2.c (process_init_constructor_record): Update bitfield
+       handling.
+       
 2008-11-12  Jason Merrill  <jason@redhat.com>
 
        PR c++/38007
index 9ab0c65e88bd827fad956dc309d52aaca644e01b..a2fce0c75968988ff3df4e36ab1988b219c33cfd 100644 (file)
@@ -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);
     }
index a131a9b06da645d872492db38592377542e364ae..b37c568c2560dd82d5bc0b7242be14cbc95a2fc5 100644 (file)
@@ -1,3 +1,8 @@
+2008-11-13  Jason Merrill  <jason@redhat.com>
+
+       PR c++/37932
+       * g++.dg/conversion/bitfield11.C: New test.
+
 2008-11-12  Jason Merrill  <jason@redhat.com>
 
        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 (file)
index 0000000..e36539c
--- /dev/null
@@ -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" }