diff options
| author | austern <austern@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-29 00:50:44 +0000 |
|---|---|---|
| committer | austern <austern@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-10-29 00:50:44 +0000 |
| commit | fe80e237e174353df47f1fad8a735c379fbfdb0e (patch) | |
| tree | 67705cf4a24be44b751b7fa552e04b2fcb416fa9 | |
| parent | a803b0bd64298a3e1d5dd23af2ec0d06e7e886d5 (diff) | |
| download | ppe42-gcc-fe80e237e174353df47f1fad8a735c379fbfdb0e.tar.gz ppe42-gcc-fe80e237e174353df47f1fad8a735c379fbfdb0e.zip | |
c++/14124
* decl.c (finish_enum): Handle packed attribute.
* parser.c (cp_parser_enum_specifier): Process trailing attributes.
* g++.dg/ext/packed7.C: New test.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@89801 138bc75d-0d04-0410-961f-82ee72b054a4
| -rw-r--r-- | gcc/cp/ChangeLog | 6 | ||||
| -rw-r--r-- | gcc/cp/decl.c | 11 | ||||
| -rw-r--r-- | gcc/cp/parser.c | 13 | ||||
| -rw-r--r-- | gcc/testsuite/ChangeLog | 5 | ||||
| -rw-r--r-- | gcc/testsuite/g++.dg/ext/packed7.C | 15 |
5 files changed, 48 insertions, 2 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 2edaa402f21..5aa869c5320 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +1004-10-28 Matt Austern <austern@apple.com> + + PR c++/14124 + * decl.c (finish_enum): Handle packed attribute. + * parser.c (cp_parser_enum_specifier): Process trailing attributes. + 2004-10-28 Mark Mitchell <mark@codesourcery.com> PR c++/17132 diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index aeb3347bb46..4d74a2a2e65 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -9504,6 +9504,7 @@ finish_enum (tree enumtype) tree maxnode; tree t; bool unsignedp; + bool use_short_enum; int lowprec; int highprec; int precision; @@ -9586,8 +9587,14 @@ finish_enum (tree enumtype) We use "int" or an "unsigned int" as the underlying type, even if a smaller integral type would work, unless the user has - explicitly requested that we use the smallest possible type. */ - for (itk = (flag_short_enums ? itk_char : itk_int); + explicitly requested that we use the smallest possible type. The + user can request that for all enumerations with a command line + flag, or for just one enumeration with an attribute. */ + + use_short_enum = flag_short_enums + || lookup_attribute ("packed", TYPE_ATTRIBUTES (enumtype)); + + for (itk = (use_short_enum ? itk_char : itk_int); itk != itk_none; itk++) { diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index ccb1ac184ce..8fed7ba9da8 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -9754,6 +9754,9 @@ cp_parser_elaborated_type_specifier (cp_parser* parser, enum-specifier: enum identifier [opt] { enumerator-list [opt] } + GNU Extensions: + enum identifier [opt] { enumerator-list [opt] } attributes + Returns an ENUM_TYPE representing the enumeration. */ static tree @@ -9791,6 +9794,16 @@ cp_parser_enum_specifier (cp_parser* parser) /* Consume the final '}'. */ cp_parser_require (parser, CPP_CLOSE_BRACE, "`}'"); + /* Look for trailing attributes to apply to this enumeration, and + apply them if appropriate. */ + if (cp_parser_allow_gnu_extensions_p (parser)) + { + tree trailing_attr = cp_parser_attributes_opt (parser); + cplus_decl_attributes (&type, + trailing_attr, + (int) ATTR_FLAG_TYPE_IN_PLACE); + } + /* Finish up the enumeration. */ finish_enum (type); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index c781e8bb28e..7667f42d1d2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +1004-10-28 Matt Austern <austern@apple.com> + + PR c++/14124 + * g++.dg/ext/packed7.C: New test. + 2004-10-28 Andrew Pinski <pinskia@physics.uc.edu> * gcc.dg/visibility-[1-9a].c: Change to use scan-hidden instead of diff --git a/gcc/testsuite/g++.dg/ext/packed7.C b/gcc/testsuite/g++.dg/ext/packed7.C new file mode 100644 index 00000000000..e2f74e02632 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/packed7.C @@ -0,0 +1,15 @@ +// PR c++/14124 +// A packed enum uses the minimal underlying type. + +// Copyright (C) 2004 Free Software Foundation, Inc. +// Contributed by Matt Austern <austern@apple.com> + +// { dg-do run } + +enum XXX { xyzzy = 3 } __attribute__((packed)); + +int main() +{ + int enumsize = sizeof(xyzzy); + return (enumsize == 1) ? 0 : 1; +} |

