diff options
author | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-20 01:52:35 +0000 |
---|---|---|
committer | jsm28 <jsm28@138bc75d-0d04-0410-961f-82ee72b054a4> | 2005-03-20 01:52:35 +0000 |
commit | aaceaa0f0578483b127c56992aa95d23561a078c (patch) | |
tree | 574e34ee47b0d94b71393462d7e047501eb6adfc | |
parent | efa312e63dbcd87973d1992d9223514e1e825727 (diff) | |
download | gcc-aaceaa0f0578483b127c56992aa95d23561a078c.tar.gz |
* 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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@96755 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/c-decl.c | 6 | ||||
-rw-r--r-- | gcc/testsuite/ChangeLog | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/bitfld-14.c | 11 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/enum3.c | 11 |
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 +}; |