diff options
| author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-05-30 21:25:02 +0000 |
|---|---|---|
| committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 2006-05-30 21:25:02 +0000 |
| commit | f5ecb8bdad7d1c93386fd9bfd6669cf0f51550b4 (patch) | |
| tree | 4a0522dc4f55cb8eb61381e3632191ea2dbb06e2 | |
| parent | ce0e61fed0838e6ac8b861d3984a808adec45a44 (diff) | |
| download | ppe42-gcc-f5ecb8bdad7d1c93386fd9bfd6669cf0f51550b4.tar.gz ppe42-gcc-f5ecb8bdad7d1c93386fd9bfd6669cf0f51550b4.zip | |
PR c++/27803
* class.c (check_bitfield_decl): Ensure that all bitfields have
integral type.
PR c++/27803
* g++.dg/parse/bitfield1.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@114245 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
| -rw-r--r-- | gcc/cp/class.c | 24 | ||||
| -rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
| -rw-r--r-- | gcc/testsuite/g++.dg/parse/bitfield1.C | 11 |
4 files changed, 34 insertions, 12 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 03db7156955..fcfb7f30a61 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2006-05-30 Mark Mitchell <mark@codesourcery.com> + + PR c++/27803 + * class.c (check_bitfield_decl): Ensure that all bitfields have + integral type. + 2006-05-29 Kazu Hirata <kazu@codesourcery.com> * pt.c (convert_nontype_argument): Fix a typo in an error diff --git a/gcc/cp/class.c b/gcc/cp/class.c index f592fe6805a..a1460c0e58d 100644 --- a/gcc/cp/class.c +++ b/gcc/cp/class.c @@ -2625,21 +2625,25 @@ static void check_bitfield_decl (tree field) { tree type = TREE_TYPE (field); - tree w = NULL_TREE; + tree w; + + /* Extract the declared width of the bitfield, which has been + temporarily stashed in DECL_INITIAL. */ + w = DECL_INITIAL (field); + gcc_assert (w != NULL_TREE); + /* Remove the bit-field width indicator so that the rest of the + compiler does not treat that value as an initializer. */ + DECL_INITIAL (field) = NULL_TREE; /* Detect invalid bit-field type. */ - if (DECL_INITIAL (field) - && ! INTEGRAL_TYPE_P (TREE_TYPE (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; } - - /* Detect and ignore out of range field width. */ - if (DECL_INITIAL (field)) + else { - w = DECL_INITIAL (field); - /* Avoid the non_lvalue wrapper added by fold for PLUS_EXPRs. */ STRIP_NOPS (w); @@ -2676,10 +2680,6 @@ check_bitfield_decl (tree field) warning (0, "%q+D is too small to hold all values of %q#T", field, type); } - /* Remove the bit-field width indicator so that the rest of the - compiler does not treat that value as an initializer. */ - DECL_INITIAL (field) = NULL_TREE; - if (w != error_mark_node) { DECL_SIZE (field) = convert (bitsizetype, w); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ecc1cc14f9a..1cc2f13451b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2006-05-30 Mark Mitchell <mark@codesourcery.com> + + PR c++/27803 + * g++.dg/parse/bitfield1.C: New test. + 2006-05-30 Roger Sayle <roger@eyesopen.com> * gcc.target/ppc-eq0-1.c: New test case. diff --git a/gcc/testsuite/g++.dg/parse/bitfield1.C b/gcc/testsuite/g++.dg/parse/bitfield1.C new file mode 100644 index 00000000000..70fe5cbd714 --- /dev/null +++ b/gcc/testsuite/g++.dg/parse/bitfield1.C @@ -0,0 +1,11 @@ +// PR c++/27803 + +struct A +{ + double i : 8; // { dg-error "type" } +}; + +void foo(A& a) +{ + (char)a.i; +} |

