aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2007-10-29 22:41:29 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2007-10-29 22:41:29 +0100
commite7df01809dbc84b6eebe815e87d51eb8e470b6b9 (patch)
tree15a3218c6d929010c60756849df159d3e24042b7 /gcc
parent324d22176d781176c004d9ff77d7f9513b013cd7 (diff)
downloadgcc-e7df01809dbc84b6eebe815e87d51eb8e470b6b9.zip
gcc-e7df01809dbc84b6eebe815e87d51eb8e470b6b9.tar.gz
gcc-e7df01809dbc84b6eebe815e87d51eb8e470b6b9.tar.bz2
re PR c++/33841 (ICE with non-integral bit-field)
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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog9
-rw-r--r--gcc/cp/class.c13
-rw-r--r--gcc/testsuite/ChangeLog5
-rw-r--r--gcc/testsuite/g++.dg/other/bitfield3.C17
4 files changed, 37 insertions, 7 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 8e2323b..c9b2325 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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>
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 54dc14c..4453b34 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -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,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 3b27043..ce4076d 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -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
index 0000000..b9726c2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/other/bitfield3.C
@@ -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> {};