From 3ef0a05e848ce72b6d5224893e94ed790980c463 Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 26 Feb 2008 18:09:02 +0000 Subject: [PATCH] PR c++/35315 * attribs.c (decl_attributes): Leave ATTR_FLAG_TYPE_IN_PLACE alone if it's the naming decl for the type's main variant. * cp/decl.c (grokdeclarator): Allow a typedef of an unnamed struct to name the struct for linkage purposes even if it has attributes. (start_decl): In that case, set ATTR_FLAG_TYPE_IN_PLACE. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@132681 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 6 ++++++ gcc/attribs.c | 6 +++++- gcc/cp/ChangeLog | 9 ++++++++- gcc/cp/decl.c | 14 +++++++++++--- gcc/testsuite/g++.dg/ext/attrib32.C | 11 +++++++++++ 5 files changed, 41 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ext/attrib32.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 35ee86e328b..02f55c96335 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2008-02-26 Jason Merrill + + PR c++/35315 + * attribs.c (decl_attributes): Leave ATTR_FLAG_TYPE_IN_PLACE + alone if it's the naming decl for the type's main variant. + 2008-02-26 Tom Tromey * system.h (USE_MAPPED_LOCATION): Poison. diff --git a/gcc/attribs.c b/gcc/attribs.c index 31b92cad508..767035b5dd1 100644 --- a/gcc/attribs.c +++ b/gcc/attribs.c @@ -280,7 +280,11 @@ decl_attributes (tree *node, tree attributes, int flags) if (spec->type_required && DECL_P (*anode)) { anode = &TREE_TYPE (*anode); - flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE; + /* Allow ATTR_FLAG_TYPE_IN_PLACE for the type's naming decl. */ + if (!(TREE_CODE (*anode) == TYPE_DECL + && *anode == TYPE_NAME (TYPE_MAIN_VARIANT + (TREE_TYPE (*anode))))) + flags &= ~(int) ATTR_FLAG_TYPE_IN_PLACE; } if (spec->function_type_required && TREE_CODE (*anode) != FUNCTION_TYPE diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index f56c61c7310..2a06b6f9adc 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2008-02-26 Jason Merrill + + PR c++/35315 + * decl.c (grokdeclarator): Allow a typedef of an unnamed struct + to name the struct for linkage purposes even if it has attributes. + (start_decl): In that case, set ATTR_FLAG_TYPE_IN_PLACE. + 2008-02-26 Tom Tromey * parser.c (eof_token): Remove old location code. @@ -181,7 +188,7 @@ 2008-02-12 Jason Merrill PR c++/34824 - * call.c (convert_like_real): Pass LOOKUP_ONLYCONVERTING to build_temp + * call.c (convert_like_real): Pass LOOKUP_NO_CONVERSION to build_temp if we're doing conversions to call a user-defined conversion function. 2008-02-12 Steven Bosscher diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c index 5a5a81a4d01..52a600440f9 100644 --- a/gcc/cp/decl.c +++ b/gcc/cp/decl.c @@ -3957,6 +3957,7 @@ start_decl (const cp_declarator *declarator, tree type; tree context; bool was_public; + int flags; *pushed_scope_p = NULL_TREE; @@ -4018,8 +4019,17 @@ start_decl (const cp_declarator *declarator, TREE_STATIC (decl) = 1; } + /* If this is a typedef that names the class for linkage purposes + (7.1.3p8), apply any attributes directly to the type. */ + if (TREE_CODE (decl) == TYPE_DECL + && TAGGED_TYPE_P (TREE_TYPE (decl)) + && decl == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (decl)))) + flags = ATTR_FLAG_TYPE_IN_PLACE; + else + flags = 0; + /* Set attributes here so if duplicate decl, will have proper attributes. */ - cplus_decl_attributes (&decl, attributes, 0); + cplus_decl_attributes (&decl, attributes, flags); /* Dllimported symbols cannot be defined. Static data members (which can be initialized in-class and dllimported) go through grokfield, @@ -8556,8 +8566,6 @@ grokdeclarator (const cp_declarator *declarator, && TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL && TYPE_ANONYMOUS_P (type) - /* Don't do this if there are attributes. */ - && (!attrlist || !*attrlist) && cp_type_quals (type) == TYPE_UNQUALIFIED) { tree oldname = TYPE_NAME (type); diff --git a/gcc/testsuite/g++.dg/ext/attrib32.C b/gcc/testsuite/g++.dg/ext/attrib32.C new file mode 100644 index 00000000000..523015cb142 --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/attrib32.C @@ -0,0 +1,11 @@ +// PR c++/35315 + +typedef union { int i; } U __attribute__((transparent_union)); + +static void foo(U) {} +static void foo(int) {} + +void bar() +{ + foo(0); +} -- 2.11.0