re PR c++/33841 (ICE with non-integral bit-field)
authorJakub Jelinek <jakub@redhat.com>
Mon, 29 Oct 2007 21:41:29 +0000 (22:41 +0100)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 29 Oct 2007 21:41:29 +0000 (22:41 +0100)
PR c++/33841
* class.c (check_bitfield_decl): Don't set field's type to error_mark_node
for non-integral type bitfields.  Return true if bitfield is correct, false
error has been diagnosed.
(check_field_decls): If check_bitfield_decl returned false, call also
check_field_decl.

* g++.dg/other/bitfield3.C: New test.

From-SVN: r129736

gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/bitfield3.C [new file with mode: 0644]

index 8e2323bb8bb17764e17deb2272284e8cc60afee8..c9b232563197bc0af90eddf3aa442126e916b512 100644 (file)
@@ -1,3 +1,12 @@
+2007-10-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/33841
+       * class.c (check_bitfield_decl): Don't set field's type to error_mark_node
+       for non-integral type bitfields.  Return true if bitfield is correct, false
+       error has been diagnosed.
+       (check_field_decls): If check_bitfield_decl returned false, call also
+       check_field_decl.
+
 2007-10-28  Paolo Carlini  <pcarlini@suse.de>
            Mark Mitchell  <mark@codesourcery.com>
 
index 54dc14c17ef53cd33c00f2784aa32581492e6e23..4453b346a69a7467ebfaa11ec13a85014d5c2832 100644 (file)
@@ -139,7 +139,7 @@ static tree build_vtbl_ref_1 (tree, tree);
 static tree build_vtbl_initializer (tree, tree, tree, tree, int *);
 static int count_fields (tree);
 static int add_fields_to_record_type (tree, struct sorted_fields_type*, int);
-static void check_bitfield_decl (tree);
+static bool check_bitfield_decl (tree);
 static void check_field_decl (tree, tree, int *, int *, int *);
 static void check_field_decls (tree, tree *, int *, int *);
 static tree *build_base_field (record_layout_info, tree, splay_tree, tree *);
@@ -2655,9 +2655,9 @@ add_fields_to_record_type (tree fields, struct sorted_fields_type *field_vec, in
 
 /* FIELD is a bit-field.  We are finishing the processing for its
    enclosing type.  Issue any appropriate messages and set appropriate
-   flags.  */
+   flags.  Returns false if an error has been diagnosed.  */
 
-static void
+static bool
 check_bitfield_decl (tree field)
 {
   tree type = TREE_TYPE (field);
@@ -2675,7 +2675,6 @@ check_bitfield_decl (tree field)
   if (!INTEGRAL_TYPE_P (type))
     {
       error ("bit-field %q+#D with non-integral type", field);
-      TREE_TYPE (field) = error_mark_node;
       w = error_mark_node;
     }
   else
@@ -2720,12 +2719,14 @@ check_bitfield_decl (tree field)
     {
       DECL_SIZE (field) = convert (bitsizetype, w);
       DECL_BIT_FIELD (field) = 1;
+      return true;
     }
   else
     {
       /* Non-bit-fields are aligned for their type.  */
       DECL_BIT_FIELD (field) = 0;
       CLEAR_DECL_C_BIT_FIELD (field);
+      return false;
     }
 }
 
@@ -3037,9 +3038,7 @@ check_field_decls (tree t, tree *access_decls,
 
       /* We set DECL_C_BIT_FIELD in grokbitfield.
         If the type and width are valid, we'll also set DECL_BIT_FIELD.  */
-      if (DECL_C_BIT_FIELD (x))
-       check_bitfield_decl (x);
-      else
+      if (! DECL_C_BIT_FIELD (x) || ! check_bitfield_decl (x))
        check_field_decl (x, t,
                          cant_have_const_ctor_p,
                          no_const_asn_ref_p,
index 3b2704314529b68ac87c909a03c957bd905404b2..ce4076d035dd60df775a75cbb54a8cbab2352228 100644 (file)
@@ -1,3 +1,8 @@
+2007-10-29  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c++/33841
+       * g++.dg/other/bitfield3.C: New test.
+
 2007-10-29  Richard Guenther  <rguenther@suse.de>
 
        * gcc.dg/tree-ssa/ssa-copyprop-1.c: Scan optimized dump.
diff --git a/gcc/testsuite/g++.dg/other/bitfield3.C b/gcc/testsuite/g++.dg/other/bitfield3.C
new file mode 100644 (file)
index 0000000..b9726c2
--- /dev/null
@@ -0,0 +1,17 @@
+// PR c++/33841
+// { dg-do compile }
+
+template<int> struct A
+{
+  struct {} : 2;       // { dg-error "with non-integral type" }
+};
+
+template<int> struct B
+{
+  int a;
+  struct {} : 2;       // { dg-error "with non-integral type" }
+  int b;
+};
+
+struct C : A<0> {};
+struct D : B<0> {};