c-decl.c (check_bitfield_type_and_width): Require bit-field width to have integer...
authorJoseph Myers <joseph@codesourcery.com>
Sun, 20 Mar 2005 01:52:35 +0000 (01:52 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Sun, 20 Mar 2005 01:52:35 +0000 (01:52 +0000)
* 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.

testsuite:
* gcc.dg/bitfld-14.c, gcc.dg/enum3.c: New tests.

From-SVN: r96755

gcc/ChangeLog
gcc/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/bitfld-14.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/enum3.c [new file with mode: 0644]

index 4742196813b5157ca81515dbfb02884e18b7809f..a3ab05c3552e30460e320b7b42b32e1fcb512af3 100644 (file)
@@ -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
index 103b50db0fc0cf476676432d54acd0a618c98168..42f6561e4986b083b10e2c0aa91cc1a55a001d2f 100644 (file)
@@ -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;
index 6af630a730d17fb91ef3422d273f5f5131bf9cfa..7921dd4ff161116062681e695b43fdad329f2dff 100644 (file)
@@ -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 (file)
index 0000000..eca0b03
--- /dev/null
@@ -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 (file)
index 0000000..ba3c1da
--- /dev/null
@@ -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
+};