c-decl.c (check_bitfield_type_and_width): Require bit-field width to have integer type.

* 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
This commit is contained in:
Joseph Myers 2005-03-20 01:52:35 +00:00 committed by Joseph Myers
parent 57e4253f85
commit 411ffa02ae
5 changed files with 36 additions and 2 deletions

View 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

View 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;

View 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

View File

@ -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;
};

View File

@ -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
};