re PR c++/36410 (ICE with transparent union)
authorJason Merrill <jason@redhat.com>
Wed, 19 Nov 2008 21:35:27 +0000 (16:35 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Wed, 19 Nov 2008 21:35:27 +0000 (16:35 -0500)
        PR c++/36410
        * decl2.c (grokfield): Pass ATTR_FLAG_TYPE_IN_PLACE for a typedef
        that names a class for linkage purposes.

From-SVN: r142019

gcc/cp/ChangeLog
gcc/cp/decl2.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/attrib32.C

index 12a826d..5e47e58 100644 (file)
@@ -1,5 +1,9 @@
 2008-11-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/36410
+       * decl2.c (grokfield): Pass ATTR_FLAG_TYPE_IN_PLACE for a typedef
+       that names a class for linkage purposes.
+
        PR c++/37563
        * parser.c (cp_parser_pseudo_destructor_name): A pseudo-destructor
        name is not a declaration.
index b326752..a0ae6e4 100644 (file)
@@ -803,7 +803,17 @@ grokfield (const cp_declarator *declarator,
        value = push_template_decl (value);
 
       if (attrlist)
-       cplus_decl_attributes (&value, attrlist, 0);
+       {
+         int attrflags = 0;
+
+         /* If this is a typedef that names the class for linkage purposes
+            (7.1.3p8), apply any attributes directly to the type.  */
+         if (TAGGED_TYPE_P (TREE_TYPE (value))
+             && value == TYPE_NAME (TYPE_MAIN_VARIANT (TREE_TYPE (value))))
+           attrflags = ATTR_FLAG_TYPE_IN_PLACE;
+
+         cplus_decl_attributes (&value, attrlist, attrflags);
+       }
 
       return value;
     }
index f1f6c28..305a992 100644 (file)
@@ -1,5 +1,8 @@
 2008-11-19  Jason Merrill  <jason@redhat.com>
 
+       PR c++/36410
+       * g++.dg/ext/attrib32.C: Add member typedef case.
+
        PR c++/37563
        * g++.dg/template/pseudodtor5.C: New test.
 
index 39363bb..77f71de 100644 (file)
@@ -20,3 +20,17 @@ void bar2(U1 u1, U2 u2)
   foo2(u1);
   foo2(u2);
 }
+
+// PR c++/36410
+struct A
+{
+  typedef union
+  {
+    int i;
+  } B __attribute__((transparent_union));
+};
+
+void foo(A::B b)
+{
+  b.i;
+}