summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog6
-rw-r--r--gcc/c-decl.c6
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.dg/bitfld-14.c11
-rw-r--r--gcc/testsuite/gcc.dg/enum3.c11
5 files changed, 36 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 4742196813b..a3ab05c3552 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@
+2005-03-20 Joseph S. Myers <joseph@codesourcery.com>
+
+ * c-decl.c (check_bitfield_type_and_width): Require bit-field
+ width to have integer type.
+ (build_enumerator): Require enumerator value to have integer type.
+
2005-03-19 Joseph S. Myers <joseph@codesourcery.com>
* doc/extend.texi (__builtin_inf): Move statement about INFINITY
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 103b50db0fc..42f6561e498 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -3642,7 +3642,8 @@ check_bitfield_type_and_width (tree *type, tree *width, const char *orig_name)
/* Detect and ignore out of range field width and process valid
field widths. */
- if (TREE_CODE (*width) != INTEGER_CST)
+ if (!INTEGRAL_TYPE_P (TREE_TYPE (*width))
+ || TREE_CODE (*width) != INTEGER_CST)
{
error ("bit-field %qs width not an integer constant", name);
*width = integer_one_node;
@@ -5633,7 +5634,8 @@ build_enumerator (tree name, tree value)
undeclared identifier) - just ignore the value expression. */
if (value == error_mark_node)
value = 0;
- else if (TREE_CODE (value) != INTEGER_CST)
+ else if (!INTEGRAL_TYPE_P (TREE_TYPE (value))
+ || TREE_CODE (value) != INTEGER_CST)
{
error ("enumerator value for %qE is not an integer constant", name);
value = 0;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index 6af630a730d..7921dd4ff16 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2005-03-20 Joseph S. Myers <joseph@codesourcery.com>
+
+ * gcc.dg/bitfld-14.c, gcc.dg/enum3.c: New tests.
+
2005-03-19 Tobias Schlueter <tobias.schlueter@physik.uni-muenchen.de>
PR fortran/18525
diff --git a/gcc/testsuite/gcc.dg/bitfld-14.c b/gcc/testsuite/gcc.dg/bitfld-14.c
new file mode 100644
index 00000000000..eca0b03def0
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/bitfld-14.c
@@ -0,0 +1,11 @@
+/* Test for non-integer bit-field widths. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+enum e { E, F };
+struct s {
+ int a : (void *)4; /* { dg-error "error: bit-field 'a' width not an integer constant" } */
+ int b : (enum e)F;
+ int c : (_Bool)1;
+};
diff --git a/gcc/testsuite/gcc.dg/enum3.c b/gcc/testsuite/gcc.dg/enum3.c
new file mode 100644
index 00000000000..ba3c1da15e3
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/enum3.c
@@ -0,0 +1,11 @@
+/* Test for non-integer enum values. */
+/* Origin: Joseph Myers <joseph@codesourcery.com> */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+enum e { E, F };
+enum e2 {
+ E1 = (void *)4, /* { dg-error "error: enumerator value for 'E1' is not an integer constant" } */
+ E2 = (enum e)F,
+ E3 = (_Bool)1
+};